0% found this document useful (0 votes)
339 views4 pages

Dry Run 10

The document contains code snippets in Java. It includes for loops, if/else statements, methods, classes, arrays, and operations on variables and strings. Some snippets print output, while others assign values or perform calculations without output. Multiple choice and true/false questions are also included about Java concepts and code behavior.

Uploaded by

anshi
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)
339 views4 pages

Dry Run 10

The document contains code snippets in Java. It includes for loops, if/else statements, methods, classes, arrays, and operations on variables and strings. Some snippets print output, while others assign values or perform calculations without output. Multiple choice and true/false questions are also included about Java concepts and code behavior.

Uploaded by

anshi
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/ 4

a)int i; b) c) if((a!

=b) || (b<4))
for(i=5;i>=1;i--) System.out.println(“Incredible”+” System.out.println(a+b);
{ \n”+”world”); else if((a>b) && (b<5))
if(i%2==1) System.out.println(a*b);
continue; else
System.out.print(i+” “); System.out.println(a%b);
}
If i)a=16,b=12 ii)a=27,b=28
d) int i; e)Write the value of d:- f) int a,b;
for(i=5;i>10;i++) a=25,b=35,c=11; for(a=6,b=4;a<=24;a=a+6)
System.out.println(i); i)d=!(a==0||a>b || !(b<0)); {if(a%b==0)
System.out.print(i*4); ii)d=!(a>b)&&(a<b&&b>0); break;
}
System.out.println(a);

g)class a h) if(a<b) i) {if(code==1)


{public static void main() {if(b!=2) System.out.println(“single digit ”);
{ int m=5,n=2,p=m*n; {c=a+b;} else if(code==11)
if(m>p) else{c=a-b;}} System.out.println(“double digit”)
System.out.println(m*m); else else
else c=a*b; System.out.println(“it is a special
System.out.println(m*p); System.out.println(c);} character”);}
If i)a=16,b=22 ii)a=27,b=18
}} i)code =1 ii)code=11 iii)code=214
iv)code=7167
j)Write the dry-run and output:- k) char ch=’F’; l) int i=1;int d=5;
int a=6,b=8,d=9;boolean x; int m=ch; do{
x=!(!((a>b)&&(a>d))); m=m+5; d=d*2;
System.out.println(x); System.out.println(m+” “+ch); System.out.println(d);
i++;
}while(i<=5);

m) for(int i=3;i<=4;i++) n) int m=5,n=10; o) for(int m=5;m<=20;m+=5)


{for(int j=2;j<i;j++) while(n>=1) {if(m%3==0)
{System.out.print(“”);} {System.out.println(m*m); break;
System.out.println(“WIN”);} n--; else
} if(m%5==0)
System.out.println(m);
continue;
}

p) char ch; q) System.out.println(“The king r) int x=2,y=50;


int x=65; said\”Begin at the beginning!\”to do{++x;y-=x++;}while(x<=10);
do{ch=(char)x;System.out.print(ch+” “); me.”); System.out.println(y);
if(x%10==0)
break;
++x;
}while(x<=100);

s) int i,sum=0; t)int bob(int b) u) int i;


for(i=1;i<=9;i+=2); {int c=5; int a[]={121,130,145,150};
System.out.println(i); c*=b++ - (--b)/8; for( i=0;i<4;i++)
System.out.println(“sum=”+sum); return c; {if(a[i]%2==0)
} {System.out.print (a[i]);}
else
{System.out.print (a[i]*a[i]);}
}
System.out.println();
System.out.println(a[i-1]);

v) int n[]={1,2,3,5,7,9,13,16}; w)class Test x) int a=8,b=10,c=15 ;


x=Math.pow(n[3],n[2]); {public static int varOne=10; a+=a++ + (- - a + c++)+b%a;
y=Math.sqrt(n[5])+Math.sqrt(n[7]); public static void method1() System.out.println(a+”,’+b+”,”+c);}
{int varOne=25;
System.out.println(varOne);}
public static void method2()
{System.out.println(varOne);}
public void Test()
{method1();
method2();}}
y) String str="STRING"; z) String x=”Loyola school”; 1) If int x[]={4,3,7,8,9,10}; What are the
System.out.print(str.charAt(2)+" String y=”Bhubaneswar”; values of p and q?
"+str.charAt(3)); System.out.println(x.substring(1,5 (i)p=x.length
System.out.println(str.substring(1,3).equals(st )); (ii)q=x[2]+x[5]*x[1]
r.substring(3,4))); System.out.println(x.indexOf(x.ch
System.out.println(str.startsWith("ST")); arAt(4)));
System.out.println(str.indexOf('R')); System.out.println(y+x.substring(
5));
System.out.println(x.equals(y));

2) void find(int a,int b) 3) If a parameterised constructor 4) What is the output of the following:
{int p=1; Abc(double num,short a) exists in String a="Java is programming language \
for(int j=1;j<=b;j++) a class,which of the following n developed by \t\'James Gosling\'";
p=p*a; valid java statement calls this System. out. println(a);
System.out.println(p); constructor implicitly:-
} a)ABC obj=new();
If find(5,3) is invoked b)ABC obj=new ABC(5.52,2);
c)Abc obj=new Abc(10.89,4);
d)All of the above
5) What is the value of m after evaluating the 6) Predict output of the following: 7) Give the output of the following java
following expression: m - = 9%++n + ++n/2; (i) statements: (i)
when int m=10,n=6 Math.pow(25,0.5)+Math.ceil(4.2) "TRANSPARENT".toLowerCase(); (ii)
(ii) Math.round ( 14.7 ) + "TRANSPARENT".compareTo("TRANSITION
Math.floor ( 7.9) ")
8) What will be the output of the following 9) What will be the output of the 10) int a[]=new int[3];
program segments? following program segments? int i,j,c=10;
(i) String s = “application”; (i) String s = “Loyola school”; for(i=0;i<3;i++)
int p = s.indexOf(“a”); int p = s.indexOf(“a”); a[i]=2*c++;
System.out.println(p); System.out.println(p); for(i=a.length-1;i>=0;i--)
System.out.println(p+s); System.out.println(p+s); System.out.println(a[i]+"\t"+2*a[i]);
(ii) String st = “PROGRAM”; (ii) String st = “Bhubaneswar”;
System.out.println(st.indexOf(st.charAt(4))) System.out.println(st.indexOf(st.c
harAt(4)))
11) Find the output:- 12) int a=2,b=3,c=9; 13) int i,j;
static void Result(int num) c*=a--+ ++b*++c; for(i=10;i>=2;i-=2)
{int System.out.println(a+” “+b+” “+c); {for(j=i;j>=2;j-=2)
s=num*num,c=s*num;System.out.println(s);} {System.out.print(i*j);
static int call(int y) }System.out.println();}
{return y*y-y;}
static void main()
{int z=call(4);Result(z);}
14)class Exam 15) Write the output of:  {int 16) int n=6,s=0;
{ int a=0,b=0; a=6,b=8,c=10,d=15; int f=a++ - (-- for( int i=1;i<=2;i++)
void Test(int c){a=5;b=c; b)*c--+ --d; for(int j=1;j<n;j++)
System.out.println("A="+a); System.out.println(a+” “+b+” if(n%j==0)
System.out.println("B="+b);} “+c+” “+d+ “ “+f); s+=j;
public void main() System.out.println(s);
{
Exam E1=new Exam(); a=16;b=25; int d=42;
System.out.println("a+b"+a+b); E1.Test(9);
d=a+b; System.out.println("Value of d="+d);
Write the output of the above code.
17) class point 18) int check(int x,int y) 19) Write the output:-
{int x,y; {int a,s,l; String s1=”jolly”; String s2=”fellow”;
point(int a,int b) if(x<y) System.out.println(s1.substring(0).concat(
{x=a;y=b;} {s=x;l=y;} s2.substring(2)));
void midpoint(point p,point q) else System.out.println(s2.toUpperCase());
{this.x=(p.x+q.x)/2; {s=y;l=x;}
this.y=(p.y+q.y)/2;} a=l;
void display() while(a%s!=0)
{System.out.println("Mid point {a+=1;}
coordinates"+x+"&"+y);} return a;}
public static void main() i)What value will be returned for
{point ob1=new point(50,100); function check(6,5)
point ob2=new point(10,20); ii)Write the main block to send
ob2.midpoint(ob1,ob2); the values and print the returned
ob2.display();}} value.

20) String 21) int i; 22) System.out.println("India".concat("is


arr[]={“DELHI”,”CHENNAI”,”MUMBAI”,”LUCK int a[]={8,9,10,12,13}; my country"));
NOW”,”JAIPUR”}; for(i=1;i<a.length;i++) String str="Patriot!";
System.out.println(arr[0].length()>arr[3].lengt {if(i%2==0) boolean a=str.endsWith("riot!");
h()); System.out.println(a[i]); System.out.println(a);
System.out.print(arr[4].substring(0,3)); else boolean b=str.startsWith("pat");
System.out.println(a[i]*a[i]); System.out.println(b);
System.out.println(Math.floor(4.3));

a) rewrite into if:- b)rewrite into multiple branching c)rewrite into ternary:-
int max=((a>b)&&(a>c))?a:((b>a)&&(b>c))?b:c; statement:- if(c==true)
If(cate==’a’) p+=(d*v);
type=”agricultural”; else
else if(cate==’d’) p-=(d*v);
type=”domestic”;
else if(cate==’c’)
type=”commercial”;
else
type=”personal”;
d)Rewrite into if-else-if :- e) rewrite into for:- f)write a prototype for function chk,
switch(code) char ch; which accepts two string parameters
{case ‘0’:System.out.println(“zero);break; int x=65; and returns the length of the longer
case ‘1’: do{ch=(char)x;System.out.print(ch+” “); string.
case ‘2’:System.out.println(“one and two”); if(x%10==0)
default:System.out.println(“None”);} break;
++x;
}while(x<=100);

g)Rewrite the following loop using for loop: h) Write the prototype of a function i) Write a statement in Java for
while (true)
System.out.print("*");
search which takes two arguments a
string and a character and returns an
√ a+b3
integer value.
¿ a−b∨¿ ¿

j) Write a java statement for each to perform k) Write a statement in Java for l)Write a statement to check if the 1st
the following task: (i) Find and display the 1 2 3 character in a string str,is blank.
r+
position of the last space in a string str. (ii) 3 x
Extract the second character of the string str.
m) Correct the errors:- n)rectify:- o) )Rewrite the following decision
Void meth1() int max=(a>b)?(a>c)?a:b:c; making statements using conditional
{String s=”work on your strengths”; operator:-
String ex=s.substring(9,10); i)if(x>0) flag=1;
If(ex==” “) else flag=0;
System.out.println(“Bingo”); ii)if(m==0)
Else System.out.print(“Hello”);
System.out.println(“OHHH!”); else System.out.print(“Good Day”);
p) Write java expression for the following:- q) Rewrite using more than one –if:- r) Rewrite using multiple branching
√ (p−a)( p−b)( p−c) if(tm>250 && em>80 && mm>95) statement:
a)r= b)v= e=’y’;else e=’N’; if(code=’A’)
3
c)Rewrite using ‘while’: a=”Accountant”;
5 x 3+2 y
{m=1;n=0; elseif(code==’c’||code==’G’)
x+ y for( ;m+n<19;n++) a=”Grade-iv”;
{Sopln(“Hello”);m+=10;} else
a=”Financial Advisor”;

You might also like