School of Computer Science Engineering and Technology
Course- BTech Type- Core
Course Code- CSET109 Course Name- Object Oriented Programming Using Java
Year- First Semester- Even Batch- BTech 2nd Semester
Tutorial-3
Tutorial No. Name CO1 CO2 CO3
3 Basics -- --
Objective: The main objective of this tutorial is to learn about the basics of Java language.
3.1 Analyse the given program segment and answer the following questions:
for(int i = 3; i <=4; i++)
{
for(int j=2; j<i; j++)
{
System.out.print("*");
}
System.out.println("Simply");
}
(i) How many times in total will the inner loop execute?
(ii) Write the output of the program segment.
3.2 Give the output of the following
program. int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
System.out.print(j);
System.out.println();
}
3.3 Convert following do-while loop into for loop.
int i=1;
int d=5;
do{ d=
d*2
System.out.println(d);
i++;
}while(i<=5);
School of Computer Science Engineering and Technology
3.4 What will be the output error in the following
program?
public class Test {
public static void main(String[] args)
{
for (int i = 0; i < 10; i++)
int x = 10;
}
}
3.5 What will be the output of the following program?
public class Test {
public static void main(String[] args)
{
int i = 0;
for (System.out.println("HI"); i < 1; i++)
System.out.println("HELLO");
}
}
3.6 What will be the output of the following code?
int a, b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a % b == 0)
break;
}
System.out.println(a);
3.7 What will be the output of the following code ?
public class LoopExample {
public static void main(String[] args) {
int i = 55;
for(; i<70; i++){
System.out.print(" "+i);
i++;
}
}
}
School of Computer Science Engineering and Technology
3.8 What will be the output of the following code ?
public class A
{
public static void main(String [] para)
{
int i=0;
while(i<10)
{
++i;
System.out.print(i+ " ");
}
}
}
3.9 What will be the output of the following code?
public class Newexample {
public static void main(String[] args) {
int i=0;
while(true){
++i;
System.out.print(i+ " ");
if(i==10){
break;
}
}
}
}