0% found this document useful (0 votes)
52 views18 pages

Java 1.1 PARAM

The document describes 4 experiments conducted by a student to learn about different types of loops in Java. Experiment 1 uses a for loop to print a multiplication table backwards. Experiment 2 uses a for-each loop to retrieve elements from an array. Experiment 3 uses nested loops to print an inverted right triangle star pattern. Experiment 4 demonstrates an infinite loop. The student's name, UID, hardware/software details, code screenshots and outputs are provided for each experiment.

Uploaded by

Mohsin kakroo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views18 pages

Java 1.1 PARAM

The document describes 4 experiments conducted by a student to learn about different types of loops in Java. Experiment 1 uses a for loop to print a multiplication table backwards. Experiment 2 uses a for-each loop to retrieve elements from an array. Experiment 3 uses nested loops to print an inverted right triangle star pattern. Experiment 4 demonstrates an infinite loop. The student's name, UID, hardware/software details, code screenshots and outputs are provided for each experiment.

Uploaded by

Mohsin kakroo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

University Institute of Engineering

Department of Computer Science & Engineering

Experiment: 1.1

Student Name: Rajendra Prasad Issar UID: 21BCS9316


Branch: Computer Science & Engineering
Section/Group: 703B
Semester: 3rd Date of Performance:
11/08/2022
Subject Name: Object Oriented Programming Using Java
Subject Code: 21CSH-218

Introduction to for loop:

For loop is a programming language conditional iterative statement which is


used to check for certain conditions and then repeatedly execute a block of
code as long as those conditions are met

Syntax :

for(initialization ;condition ;updatiion/increment/decrement)


{
//code
};

Hardware and Software Used:


University Institute of Engineering
Department of Computer Science & Engineering

RAM : 8 GB
Operating System : Windows
HackerRank Problem :
University Institute of Engineering
Department of Computer Science & Engineering

Code/Program Code :
import java.io.*;
University Institute of Engineering
Department of Computer Science & Engineering

import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Syst
em.in));

        int N = Integer.parseInt(bufferedReader.readLine().trim());
        
if(N>=2 || N<=20){

            for(int i=1;i<=10;i++){
                System.out.println(N + " x " + i + " = "+ (N*i));
            }
        }    
        bufferedReader.close();
    }
}

ScreenShot of Code :
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

ScreenShot of Output :

1. Aim of the practical:

Write a program to print multiplication table of 12 in reverse order using for


loop.

Introduction to for loop:

For loop is a programming language conditional iterative statement which is


used to check for certain conditions and then repeatedly execute a block of
code as long as those conditions are met

Syntax :
University Institute of Engineering
Department of Computer Science & Engineering

for(initialization ;condition ;updatiion/increment/decrement)


{
//code
};

Hardware and Software Used:

RAM : 8 GB
Operating System : Windows

Code/Program Code :

public class Experiment1_1 {


public static void main(String[] args) {
System.out.println("Printing Table of 12 in Reverse Order..!!");
System.out.println("Name : Rajendra Prasad Issar\nUID :
21BCS9316");
int num = 12;
for(int i=10;i>=1;i--){
System.out.println(num + " X " + i + " = " + num*i);
}
}
}
University Institute of Engineering
Department of Computer Science & Engineering

ScreenShot of Code :

ScreenShot of Output :
University Institute of Engineering
Department of Computer Science & Engineering

2. Aim of the practical:

Write a Program to Retrieve Elements from an Array using for each loop.

Introduction to for each loop:

In Java, the for-each loop is used to iterate through elements of arrays .

Syntax :

For(dataType name : ArrayName)


{
System.out.println(name);
};

Code/Program Code :

public class Experiment1_2 {

public static void main(String[] args) {

int arr[] = {45,29,54,38,21,34,34,89};

System.out.println("Retrieving Elements of Array..!!");

System.out.println("Name : Rajendra \nUID : 21BS9316");

for(int element : arr){


University Institute of Engineering
Department of Computer Science & Engineering

System.out.println(element);

ScreenShot of Code :

ScreenShot of Output :
University Institute of Engineering
Department of Computer Science & Engineering

3. Aim of the practical:

Print the Inverted Right Triangle Star Pattern using Nested loop given
below.
University Institute of Engineering
Department of Computer Science & Engineering

Introduction to Nested loops :

A nested loop is a loop within a loop, an inner loop within the body of an
outer one.

Syntax :

for(initialization ;condition ;updation/increment/decrement)

For(initialization ;condition ;updation/increment/decrement)

//code

Code/Program Code :

public class Experiment1_3 {

public static void main(String[] args) {

System.out.println("Printing Inverted Right Triangle Star Pattern...!!");

System.out.println("Name : Rajendra \nUID:21BCS9316");

int n = 7;

for (int i=n; i>0; i--){

for(int j=0;j<i;j++){
University Institute of Engineering
Department of Computer Science & Engineering

System.out.print("*");

System.out.print("\n");

ScreenShot of Code :
University Institute of Engineering
Department of Computer Science & Engineering

ScreenShot of Output :

4. Aim of the practical:

Write a Program to print Infinite loop.


University Institute of Engineering
Department of Computer Science & Engineering

Introduction of Infinite loop:

An infinite loop is an instruction sequence that loops endlessly when a


terminating condition has not been set.

Code/Program Code :
public class Experiment1_4 {

public static void main(String[] args) {

System.out.println("Printing Infinite Loop..!!!");

System.out.println("Name : Rajendra\nUID : 21BCS9316");

for(int i=5;i>4;i++){

System.out.println("Infinite Loop");

ScreenShot of Code :
University Institute of Engineering
Department of Computer Science & Engineering

ScreenShot of Output :
University Institute of Engineering
Department of Computer Science & Engineering
University Institute of Engineering
Department of Computer Science & Engineering

Learning Outcomes :

1. Different types of loops, such as for, while and do-while


2. Nested loops
3. System.out.println()

Evaluation Grid (To be filled by Faculty):

Sr. Parameters Marks Maximum


No. Obtained Marks
1. Worksheet completion including writing 10
learning objectives/Outcomes.(To
besubmitted at the end of the day)
2. Post Lab Quiz Result. 5
3. Student Engagement in 5
Simulation/Demonstration/Performance
and Controls/Pre-Lab Questions.
Signature of Faculty (with Date): Total
Marks
Obtained:

You might also like