Output Based Questions
Output Based Questions
1. x = 5; y = 50;
while(x<=y)
{
y = y / x;
System.out.println(y);
}
2.
int m=2;
int n=15;
for(int i=1;i<5;i++)
m++;
--n;
System.out.println("m="+m);
System.out.println("n="+n);
3. int a,b;
for(a=6,b=4; a <= 4; a=a+ 6)
{
if(a%b==0)
break;
}
System.out.println(a);
4. for(int m=5;m<=20;m+=5)
if(m%3==0)
break;
else
if(m%5==0)
System.out.println(m);
continue;
5. int a=0;
while(a> - 5)
System.out.print(a+””);
System.out.print(--a*2);
System.out.println();
--a;
6.
int k,j;
for(j=1;j<=5;j+=2)
{
for(k=1;k<=j ;k++)
System.out.print(k);
System.out.println();
7.
int j, k, p=-1;
for(j= - 2;j<=1;j++)
for(k=j; k<=0;k++)
k=Math.max(j*k, p)
System.out.print(k);
p=p+2;
8.int k=5,j;
while(k>=1)
j=1;
while(j<=k)
System.out.print(j);
j++;
System.out.println();
k--;
9. int i,j;
first:
for(i=1;i<10;i+=2)
for(j=3;j>=1;j=j-2)
if(i>5)
break first;
System.out.println(“i=”+i+”j=”=j);
10.
int i,j;
first:
for(i=0;i<5;i=i+2)
second:
for(j=1;j<=10;j++)
System.out.println(“i+””+i+”j”+j)
if(J==2)
break second;
20.
int x = 5;
x-=x++*2+3* – -x;
21.
24. State the output when the following program segment is executed:
String a =“Smartphone”, b=“Graphic Art”;
String h=a.substring(2, 5);
String k=b.substring(8).toUpperCase();
System.out.println(h);
System.out.println(k.equalsIgnoreCase(h));
25. char ch ;
int x=97;
do
{
ch=(char) x;
System.out.print(ch + “ ” );
if(x%10 == 0)
break;
++x;
}while(x<=100);