OutPut Generation Set1
OutPut Generation Set1
Part 1
1>char x, y;
x = 'y';
System.out.println(x);
y = 'z';
System.out.println(y);
x = y;
System.out.println(x);
2>char ch = 'F';
int m = ch;
m=m+5;
System.out.println(m + " " + ch);
3>void test3(char c)
{
System.out.println( (int) c);
}
if 'm' is passed to c.
5>void test1(int n)
{
for(int x=1; x<=n; x++)
if(n%x == 0)
System. out.println(x);
}
if 12 is passed to n.
7>int y,p;
for (int x=1; x<=3; x++)
{
for (y=1; y<=2; y++)
{
p = x * y;
System.out.print(p);
}
System.out.println( );
}
8>int x,y;
for(x=1; x<=5; x++)
{
for(y=1; y<x; y++)
{
if(x == 4)
break;
System.out.print(y);
}
System.out.println( );
}
9>int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
System.out.print((char) b);
System.out.println( );
}
10>int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
System.out.print(j);
System.out.println();
}
11>int m=3,n=5,p=4;
if(m==n && n!=p)
{
12>int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
{
System.out.println((m+n));
System.out.println((m—n));
}
if((a==1)&&(b==1))
{
System.out.println((m*n));
System. out.println((m%n));
}
13>int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
System.out.println(r);
}
else
{
c=a/b;
System.out.println(c);
}
14>int x=1,y=1;
if(n>0)
{
x=x+1;
y=y+1;
}
What will be the value of x and y, if n assumes a value (i) 1 (ii) 0?
15>switch (opn)
{
case 'a':
System.out.println("Platform Independent");
break;
case 'b':
16>int a=10,b=12;
if(a==10&&b<=12)
a--;
else
++b;
System.out.println(a + "and" +b);
17>int a=10,b=12;
if(a>=10)
a++;
else
++b;
System.out.println(a + "and" +b);
18>int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
System.out.println(r);
}
else
{
c=a/b;
System.out.println(c);
19>int x = 1,y = 1;
if(n > 0)
{
x = x + 1;
y = y + 1;
}
System.out.println(x + " , " + y);
What will be the values of x and y, if the value of n is given as:
(i) 1
(ii) 0 ?
20>int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
21>System.out.println("nine:" + 5 + 4);
System.out.println("nine:" + (5 + 4));
24>int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
System.out.println(s);
}
25>
int a[]=new int [5];
a[0]=4; a[1]=8; a[2]=7; a[3]=12; a[4]=3;
System.out.println(a[2+1]);
28>System.out.println(Math.floor(-4.7));
System.out.println(Math.max(Math.ceil(14.55),15.5));
30>char c = 'B';
int i = 4;
System.out.println(c+i);
System.out.println((int)c+i);
31>String s= "7";
int t =Integer.parseInt(s);
t=t+1000;
System.out.println(t);
32>char c = 'B';
int i = 4;
System.out.println(c+i);
System.out.println((int)c+i);
34>int n = 97;
char ch = Character.toUpperCase((char)n);
System.out.println(ch + " Great Victory");
35>String s= "7";
int t =Integer.parseInt(s);
t=t+1000;
System.out.println(t);
36>char c = 'A';
int n = (int) c + 32;
37>char ch = 'A';
char chr = Character.toLowerCase(ch);
int n = (int)chr-32;
System.out.println((char)n + "\t" + chr);
38>char ch = 'y';
char chr = Character.toUpperCase(ch);
int p = (int) chr;
System.out.println(chr + "\t" + p);
39>char ch = '*';
boolean b = Character.isLetter(ch);
System.out.println(b);
43>String x = "Vision";
String y = "2020";
System.out.println(x.charAt(3));
44>String x = "Computer";
String y = "Applications";
System.out.println(x.equals(y));
45>String x = "Computer";
String y = "Applications";System.out.println(x.substring(1,5));
48>String x = "Computer";
String y = "Applications";System.out.println(x.indexOf(x.charAt(4)));
49>boolean p;
p = ("BLUEJ".length() > "bluej".length()) ? true: false;
50>String x = "Computer";
String y = "Applications";
System.out.println(y + x.substring(5));
53>String x = "Vision";
String y = "2020";
System.out.println(x.equals(y));
61>void strop(String s) {
char a = s.charAt(3);
int b = s.indexOf('M');
String t = s.substring(3,6);
boolean p = s.equals(t);
System.out.println(a + " " + b + " " + t + " " + p);
}
What will be the output for strop("COMPUTER")?
62>int v,s,n=550;
s = n + v > 1750? 400:200;
When,
64>Evaluate the following expressions if the values of the variables are a = 2, b = 3, and c = 9.
(a) 5* ++x;
(b) 5* x++;
68>int a=0,b=10,c=40;
a = --b + c++ + b;
System.out.println(" a = " + a);
69>Rewrite the following program segment using if-else statements instead of the ternary operator:
String grade = (marks>=90)?"A": (marks>=80)? "B": "C";
70>Rewrite the following program segment using if-else statements instead of the ternary operator:
net = (salary > 10000) ? salary - (8.33/100)*salary : salary - (5/100)*salary
71>int a = 14, b = 4;
boolean x = (a > b) ? true : false;
73>if(a > b)
{
if (a > c)
g = a;
else
g = c;
}
else if (b > c)
g = b;
else
g = c;
76>Rewrite the following program segment using if-else statements instead of the ternary operator:
c = (x >= 'A' && x<= 'Z') ? "Upper Case Letter" : "Lower Case Letter";
80>Rewrite the following program segment using if-else statements instead of the ternary operator:
81>int k=5,j=9;
k+= k++ - ++j + k;
System.out.println("k="+k);
System.out.println("j="+j);
86>int a=0,b=10,c=40;
a = --b + c++ +b;
System.out.println(" a = " + a);
88>int a=6,b=5;
a += a++ % b++ *a + b++* --b;
89>int a=6,b=5,c;
c = (a++ % b++) *a + ++a*b++;
90>Give the output of following code and mention how many times the loop will execute?
int i;
for( i=5; i>=1; i--)
{
if(i%2 == 1)
continue;
System.out.print(i+" ");
}
91>State the final value of q at the end of the following program segment after execution. Show the dry
run.
for(m=2;m<=3;++m)
{
92>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);
93>x = 1; y = 1;
if(n>0)
{
x = x + 1;
y = y + 1;
}
What will be the value of x and y, if n assumes a value:
(i) 1
(ii) 0
94>int a,b;
for(a=6;b=4; a <= 4; a=a+ 6)
{
if(a%b==0)
break;
}
System.out.println(a);
95>int k=1,i=2;
while(++i<6)
k*=i;
System.out.println(k);
96>int i;
for(i = 5; i > 10; i++)
System.out.println(i);
System.out.println(i * 4);
97>x = 5; y = 50;
while(x<=y)
98>Determine how many times the body of the loop will be executed and predict the output.
class dk4
{
public static void main(String args[])
{
int x=5,y=50;
while(x<=y)
{
y=y/x;
System.out.println(y);
}
}
}
99>class dk2
{
public static void main(String args[])
{
int i=2,k=1;
while (++i<6)
k *= i;
System.out.println(k);
}
}
100>class dk3
{
public static void main(String args[])
{
int m=2,n=15;
for(int i=1;i<=5;i++)
{
m++;--n;
System.out.println("m="+m);
System.out.println("n="+n);
}
}
}
101>for(i = -1;i<10;i++)
{
System.out.println(++i);
102>int p = 9;
while (p<=15)
{
p++;
if(p== 10)
continue;
System.out.println(p);
}
103>int a = 3;
while (a<=10)
{
a++;
if(a== 5)
continue;
System.out.println(a);
}
104>int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b == 0)
break;
}
System.out.println(a);
105>char ch ;
int x=97;
do
{
ch=(char)x;
System.out.print(ch + " " );
if(x%10 == 0)
break;
++x;
} while(x<=100);
106>int k;
for ( k = 5 ; k < = 20 ; k + = 7 )
if ( k% 6==0 )
continue;
System.out.println(k);
107>int x, y;
for (x = 9, y = 4; x <= 45; x+=9) {
108>int x=4;
x += (x++) + (++x) + x;
110>String s = "Examination";
int n = s.length();
System.out.println(s.startsWith(s.substring(5, n)));
System.out.println(s.charAt(2) == s.charAt(6));
112>String s = "malayalam";
System.out.println(s.indexOf('m'));
System.out.println(s.lastIndexOf('m'));
113>If int n[] ={1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
x=Math.pow(n[4],n[2]);
y=Math.sqrt(n[5]+[7]);
114>What is the final value of ctr after the iteration process given below, executes?
int ctr=0;
for(int i=1;i<=5;i++)
for(int j=1;j<=5;j+=2)
++ctr;
116>int k = 5, j = 9;
k += k++ – ++j + k;
System.out.println("k= " +k);
System.out.println("j= " +j);
117>int m=2;
int n=15;
120>int a = 9; a++;
System.out.println (a);
a -= a – - – a;
System .out.println (a);
124>char ch[ ]= {‘I’, ‘N’, T’, E’, ‘L’, P’, ‘E’, ‘N’, ‘T’, ‘I’, ‘U’, ‘M’};
String obj= new String(ch, 3, 4);
System.out.println(“The result is = “+ obj);