Output Generation
Part 1
1>char x, y;
x = 'y';
[Link](x);
y = 'z';
[Link](y);
x = y;
[Link](x);
2>char ch = 'F';
int m = ch;
m=m+5;
[Link](m + " " + ch);
3>void test3(char c)
{
[Link]( (int) c);
}
if 'm' is passed to c.
4>void test4(String x, String y)
{
if([Link](y) > 0)
[Link](x);
else
[Link](y);
}
if "AMIT" and "AMAN" are passed to the method.
5>void test1(int n)
{
for(int x=1; x<=n; x++)
if(n%x == 0)
System. [Link](x);
}
if 12 is passed to n.
6>void test2(int a, int b)
{
while( a != b)
{
if ( a > b)
a = a — b;
else
Surajit Acharya [9831677218 WAPP/8240524380] Page 1
a = b — a;
}
[Link](a);
}
if 4 and 17 are passed to the function.
7>int y,p;
for (int x=1; x<=3; x++)
{
for (y=1; y<=2; y++)
{
p = x * y;
[Link](p);
}
[Link]( );
}
8>int x,y;
for(x=1; x<=5; x++)
{
for(y=1; y<x; y++)
{
if(x == 4)
break;
[Link](y);
}
[Link]( );
}
9>int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
[Link]((char) b);
[Link]( );
}
10>int i,j;
for (i=0; i<4; i++)
{
for (j=i; j>=0; j--)
[Link](j);
[Link]();
}
11>int m=3,n=5,p=4;
if(m==n && n!=p)
{
Surajit Acharya [9831677218 WAPP/8240524380] Page 2
[Link](m*n);
[Link](n%p);
}
if((m!=n) || (n==p))
{
[Link](m+n);
[Link](m-n);
}
12>int a=1,b=1,m=10,n=5;
if((a==1)&&(b==0))
{
[Link]((m+n));
[Link]((m—n));
}
if((a==1)&&(b==1))
{
[Link]((m*n));
System. [Link]((m%n));
}
13>int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
[Link](r);
}
else
{
c=a/b;
[Link](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':
[Link]("Platform Independent");
break;
case 'b':
Surajit Acharya [9831677218 WAPP/8240524380] Page 3
[Link]("Object Oriented");
case 'c':
[Link]("Robust and Secure");
break;
default:
[Link]("Wrong Input");
}
When (i) opn = 'b' (ii) opn = 'x' (iii) opn = 'a'
16>int a=10,b=12;
if(a==10&&b<=12)
a--;
else
++b;
[Link](a + "and" +b);
17>int a=10,b=12;
if(a>=10)
a++;
else
++b;
[Link](a + "and" +b);
18>int b=3,k,r;
float a=15.15,c=0;
if(k==1)
{
r=(int)a/b;
[Link](r);
}
else
{
c=a/b;
[Link](c);
19>int x = 1,y = 1;
if(n > 0)
{
x = x + 1;
y = y + 1;
}
[Link](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))
Surajit Acharya [9831677218 WAPP/8240524380] Page 4
{
[Link]((m+n));
[Link]((m-n));
}
if((a==1)&&(b==1))
{
[Link]((m*n));
[Link]((m%n));
}
21>[Link]("nine:" + 5 + 4);
[Link]("nine:" + (5 + 4));
22>int m[] = {2,4,6,8};
[Link](m[1] + " " + m[2]);
23>int a[] ={2,4,6,8,10};
a[0]=23;
a[3]=a[1];
int c= a[0]+a[1];
[Link]("Sum = "+c);
24>int a[4]={2,4,6,8};
for(i=0;i<=1;i++)
{
s=a[i]+a[3-i];
[Link](s);
}
25>
int a[]=new int [5];
a[0]=4; a[1]=8; a[2]=7; a[3]=12; a[4]=3;
[Link](a[2+1]);
26>int n[] ={1,2,3,5,7,9,13,16};
double a=[Link](n[4], n[1]);
double b=[Link](n[5]+n[7]);
[Link]("a=" + a);
[Link]("b=" + b);
27>int x[] = {4, 3, 7, 8, 9, 10};
int p = [Link];
int q = x[2] + x[5] * x[1];
[Link]("p=" + p);
[Link]("q=" + q);
28>[Link]([Link](-4.7));
[Link]([Link]([Link](14.55),15.5));
Surajit Acharya [9831677218 WAPP/8240524380] Page 5
[Link]([Link](-9.4)+[Link](9.0));
[Link]([Link](3.4)+[Link](2,3));
[Link]([Link]([Link](42.5,42.25)));
[Link]([Link](-99.4));
[Link]([Link](98.5));
[Link]([Link](-0.88));
[Link]([Link](-77.66, -87.45));
[Link]([Link](-25.5, -12.5));
[Link]([Link](65.5));
[Link]([Link](-18.51));
[Link]([Link](-0.95));
29>String P = "20", Q ="19";
int a = [Link](P);
int b = [Link](Q);
[Link](a+""+b);
30>char c = 'B';
int i = 4;
[Link](c+i);
[Link]((int)c+i);
31>String s= "7";
int t =[Link](s);
t=t+1000;
[Link](t);
32>char c = 'B';
int i = 4;
[Link](c+i);
[Link]((int)c+i);
33>char ch = 'x'; int n = 5;
n = n + (int)ch;
char c = (char)n;
[Link]((char)((int)c-26));
34>int n = 97;
char ch = [Link]((char)n);
[Link](ch + " Great Victory");
35>String s= "7";
int t =[Link](s);
t=t+1000;
[Link](t);
36>char c = 'A';
int n = (int) c + 32;
Surajit Acharya [9831677218 WAPP/8240524380] Page 6
[Link]((char)n);
37>char ch = 'A';
char chr = [Link](ch);
int n = (int)chr-32;
[Link]((char)n + "\t" + chr);
38>char ch = 'y';
char chr = [Link](ch);
int p = (int) chr;
[Link](chr + "\t" + p);
39>char ch = '*';
boolean b = [Link](ch);
[Link](b);
40>String A ="26", B="100";
String D=A+B+"200";
int x= [Link](A);
int y = [Link](B);
int d = x+y;
[Link]("Result 1 = " + D);
[Link]("Result 2 = " + d);
41>String a="10", b="20";
int x=[Link](a);
int y=[Link](b);
[Link](x+y);
[Link](a+b);
42>String s1 = "phoenix"; String s2 ="island";
[Link]([Link](0).concat([Link](2)));
[Link]([Link]());
43>String x = "Vision";
String y = "2020";
[Link]([Link](3));
44>String x = "Computer";
String y = "Applications";
[Link]([Link](y));
45>String x = "Computer";
String y = "Applications";[Link]([Link](1,5));
46>String S1 = "Computer World";
String S2 = "COMPUTER WORLD";
String S3 = "Computer world";
Surajit Acharya [9831677218 WAPP/8240524380] Page 7
String S4 = "computer world";
[Link](S1 + " equals "+ S2 + " " + [Link](S2));
[Link](S1 + " equals "+ S3 + " " + [Link](S3));
[Link](S1 + " equals "+ S4 + " " + [Link](S4));
[Link](S1 + " equalsIgnoreCase "+ S4 + " " + [Link](S4));
47>String str = "Information Technology";
int p;
p = [Link]('n');
[Link](p);
48>String x = "Computer";
String y = "Applications";[Link]([Link]([Link](4)));
49>boolean p;
p = ("BLUEJ".length() > "bluej".length()) ? true: false;
50>String x = "Computer";
String y = "Applications";
[Link](y + [Link](5));
51>String str1 = "Information Technology";
String str2 = "information technology";
boolean p = [Link](str2);
[Link]("The result is " + p);
52>String n = "Computer Knowledge";
String m = "Computer Applications";
[Link]([Link](0,8).concat([Link](9)));
[Link]([Link]("e"));
53>String x = "Vision";
String y = "2020";
[Link]([Link](y));
54>String x[] = {"SAMSUNG", "NOKIA", "SONY", "MICROMAX", "BLACKBERRY"};
[Link](x[3].length());
55>String arr[]= {"DELHI", "CHENNAI", "MUMBAI", "LUCKNOW", "JAIPUR"};
[Link](arr[0].length() > arr[3].length());
[Link](arr[4].substring(0,3));
56>String n1 = "46", n2 = "64";
int total = [Link](n1) + [Link](n2);
[Link]("The sum of " + "46 " + "and" + " 64" + " is " + total);
57>String str = "Computer Applications" + 1 + 0;
[Link]("Understanding" + str);
Surajit Acharya [9831677218 WAPP/8240524380] Page 8
58>String s="Today is Test";
[Link]([Link]('T'));
[Link]([Link](0,7) + " " +"Holiday");
59>String a ="Smartphone", b="Graphic Art";
String h=[Link](2, 5);
String k=[Link](8).toUpperCase();
[Link](h);
[Link]([Link](h));
60>String s1 = "Life is Beautiful";
[Link]("Earth" + [Link](4));
[Link]([Link]("L"));
61>void strop(String s) {
char a = [Link](3);
int b = [Link]('M');
String t = [Link](3,6);
boolean p = [Link](t);
[Link](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,
(a)v = 500 (b)v = 1500
63>If a = 0, b = 30, c = 40; then find the value of 'a' when:
a += --b + c++ + b;
64>Evaluate the following expressions if the values of the variables are a = 2, b = 3, and c = 9.
(a) a - (b++) * (--c);
(b) a * (++b) % c;
65>What will be the output of the following if x = 5 initially?
(a) 5* ++x;
(b) 5* x++;
66>If a = 5, b = 9, calculate the value of a in the following expression:
a += a++ - ++b + a
67>If m = 5 and n = 2, predict the output values of m and n:
Surajit Acharya [9831677218 WAPP/8240524380] Page 9
(a) m -= n;
(b) n = m + m/n;
68>int a=0,b=10,c=40;
a = --b + c++ + b;
[Link](" 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;
72>If int y =10 then find int z = (++y * (y++ + 5));
73>if(a > b)
{
if (a > c)
g = a;
else
g = c;
}
else if (b > c)
g = b;
else
g = c;
74>int a = 18; int b = 12;
boolean t = (a > 20 && b < 15)? true : false;
75>Rewrite the following using ternary operator:
if (bill > 10000)
discount=bill*10.0/100;
else
discount=bill*5.0/100;
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";
77>Predict the output of the below Java program snippet:
c = (val + 550 < 1700)? 200: 400;
if: (a) val = 1000 (b) val = 1500
Surajit Acharya [9831677218 WAPP/8240524380] Page 10
78>Give the output of the following expression:
a+= a++ + ++a + --a + a--; when a = 7;
79>What is the value of y after the execution?
y+= ++y + y-- + --y; when int y=8
80>Rewrite the following program segment using if-else statements instead of the ternary operator:
s = (a + b < c || a + c <= b || b + c <= a) ? "Triangle is not possible": "Triangle is possible";
81>int k=5,j=9;
k+= k++ - ++j + k;
[Link]("k="+k);
[Link]("j="+j);
82>Determine the output of the following program.
public class PredictOutput2
{
public static void main(String args[])
{
int a = 6, b = 2, c = 3;
[Link]("Output 1: " + (a == b * c));
[Link]("Output 2: " + (a == (b * c)));
}
}
83>Determine the output of the following program.
public class PredictOutput3
{
public static void main(String args[])
{
int a = 2, b = 2, c = 2;
[Link]("Output 1: " + (a + 2 < b * c));
[Link]("Output 2: " + (a + 2 < (b * c)));
}
}
84>Determine the output of the following program.
public class Test
{
public static void main(String[] args)
{
int a = 1, b = 2;
[Link]("Output1: " + a + b);
Surajit Acharya [9831677218 WAPP/8240524380] Page 11
[Link]("Output2: " + (a + b));
}
}
85>Determine the output of the following program.
public class PredictOutput1
{
public static void main(String args[])
{
int a = 4, b = 2, c = 3;
[Link]("Output 1: " + (a = b * c));
[Link]("Output 2: " + (a = (b * c)));
}
}
86>int a=0,b=10,c=40;
a = --b + c++ +b;
[Link](" a = " + a);
87>int a = 10, b =12;
if(a>=10)
a++;
else
++b;
[Link](" a = " + a + " and b = " +b);
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;
[Link](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)
{
Surajit Acharya [9831677218 WAPP/8240524380] Page 12
for(n=1;n<=m;++n)
{
p=m+n-1;
if(p%3 == 0)
q += p;
else
q += p+4;
}
}
92>int m=2;
int n=15;
for(int i=1;i<5;i++)
m++;
--n;
[Link]("m="+m);
[Link]("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;
}
[Link](a);
95>int k=1,i=2;
while(++i<6)
k*=i;
[Link](k);
96>int i;
for(i = 5; i > 10; i++)
[Link](i);
[Link](i * 4);
97>x = 5; y = 50;
while(x<=y)
Surajit Acharya [9831677218 WAPP/8240524380] Page 13
{
y = y / x;
[Link](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;
[Link](y);
}
}
}
99>class dk2
{
public static void main(String args[])
{
int i=2,k=1;
while (++i<6)
k *= i;
[Link](k);
}
}
100>class dk3
{
public static void main(String args[])
{
int m=2,n=15;
for(int i=1;i<=5;i++)
{
m++;--n;
[Link]("m="+m);
[Link]("n="+n);
}
}
}
101>for(i = -1;i<10;i++)
{
[Link](++i);
Surajit Acharya [9831677218 WAPP/8240524380] Page 14
}
102>int p = 9;
while (p<=15)
{
p++;
if(p== 10)
continue;
[Link](p);
}
103>int a = 3;
while (a<=10)
{
a++;
if(a== 5)
continue;
[Link](a);
}
104>int a,b;
for (a = 6, b = 4; a <= 24; a = a + 6)
{
if (a%b == 0)
break;
}
[Link](a);
105>char ch ;
int x=97;
do
{
ch=(char)x;
[Link](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;
[Link](k);
107>int x, y;
for (x = 9, y = 4; x <= 45; x+=9) {
Surajit Acharya [9831677218 WAPP/8240524380] Page 15
if (x % y == 0)
break;
}
[Link](x);
108>int x=4;
x += (x++) + (++x) + x;
109>double x = 2.9, y = 2.5;
[Link]([Link]([Link](x), y));
[Link]([Link]([Link](x), y));
110>String s = "Examination";
int n = [Link]();
[Link]([Link]([Link](5, n)));
[Link]([Link](2) == [Link](6));
111>String s1 = "Computer", s2 = "Applications";
a = ([Link](s2));
b = ([Link](s2));
112>String s = "malayalam";
[Link]([Link]('m'));
[Link]([Link]('m'));
113>If int n[] ={1, 2, 3, 5, 7, 9, 13, 16} what are the values of x and y?
x=[Link](n[4],n[2]);
y=[Link](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;
115>String n = “Computer Knowledge”;
String m = “Computer Applications”;
[Link]([Link] (0,8). concat ([Link](9)));
[Link]([Link](“e”));
116>int k = 5, j = 9;
k += k++ – ++j + k;
[Link]("k= " +k);
[Link]("j= " +j);
117>int m=2;
int n=15;
Surajit Acharya [9831677218 WAPP/8240524380] Page 16
for(int i = 1; i<5; i++);
m++; –-n;
[Link]("m=" +m);
[Link]("n="+n);
118>char x = 'A' ; int m;
m=(x=='a') ? 'A' : ‘a’;
[Link]("m="+m);
119>int k=1, i=2;
while (++i<6)
k*=i;
[Link](k);
120>int a = 9; a++;
[Link] (a);
a -= a – - – a;
System .[Link] (a);
121>long num=729, sum 0;
for( long y= num; y> 0; y= y/10){
sum= sum + y % 10;
}
[Link]("Sum of digits = "+ sum);
122>If int y = 10 then find int z = (++y * (y++ + 5));
123>[Link](“My Friends are \n”);
[Link](“Ronit \tNihir \t”);
[Link](“and Ananya too”);
124>char ch[ ]= {‘I’, ‘N’, T’, E’, ‘L’, P’, ‘E’, ‘N’, ‘T’, ‘I’, ‘U’, ‘M’};
String obj= new String(ch, 3, 4);
[Link](“The result is = “+ obj);
125>String str1 = ”great”;
String str2= “Minds”;
[Link]([Link](0,2). Concat([Link](1)));
[Link](( “WH”+([Link](2).toUpperCase() )));
126>int a= new int(5);
for(int i=0; i<=5; i++)
a[i]= I;
Surajit Acharya [9831677218 WAPP/8240524380] Page 17