PREDICT THE OUTPUT REVISION WORKSHEET Grade 10th Icse
PREDICT THE OUTPUT REVISION WORKSHEET Grade 10th Icse
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
ii) System.out.println(“This is my First Output of the Java Program”);
System.out.print(“ I have designed it today”);
System.out.println(“What about You!!”);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
2. Write the print statement of the following output:
i) int a=25, b=30;
The Addition of 25 and 30 is 55
_____________________________________________________________________________
ii) String na= “Rohit”, nb= “Shikhar”;int runs=153;
Rohit and Shikhar made the opening partnership of 153 Runs
_____________________________________________________________________________
iii) String a= “Virat”, nb= “Dhoni” int r1=55, r2=105;
India’s Captain Virat and wicketkeeper Dhoni made 55 and 105 runs respectively
_____________________________________________________________________________
1. Why are the following Java identifiers invalid? Give reason
i) void : _______________________________________________
ii) C*2a5 : _______________________________________________
iii) $ Project : _______________________________________________
iv) Student+roll : _______________________________________________
v) break : _______________________________________________
vi) 1st_Test : _______________________________________________
2. Write the output of the following
i) System.out.println(8<15);
Page No. 1
_____________________________________________________________________________
ii) System.out.println(12!=15);
_____________________________________________________________________________
_____________________________________________________________________________
_____________________________________________________________________________
v) System.out.println( !(true));
____________________________________________________________________________
______________________________________________________________________
System.out.println(5>3 || !(false));
______________________________________________________________________
System.out.println(“We are the Students of\“Computer Application\” Class”);
______________________________________________________________________
3. What is the resultant data types if the following implicit conversions are performed?
int i; float f; double d; char c; byte b;
i) i+c/b; _____________________________
ii) f+c-d+i _____________________________
iii) c/b+f+i _____________________________
iv) b+f-i/c _____________________________
4. What is the resultant data types if the following explicit conversions are performed?
int i; float f; double d; char c; byte b;
i) (char)i+c/b; _____________________________
ii) (int)f+c-d+i _____________________________
iii) c/b+(double)f+i _____________________________
iv) b+f-i/(int)d _____________________________
v) (float)f+(int)d _____________________________
vi) Write the output data type of the given expression
int a; float f; double d; char c;
(float) (a/f)-d*c; _____________________________
5. Write the output of the following
double num1=56.8, num2=6.7;
i) System.out.println((int)num1+num2); _______________________________
ii) System.out.println((int) (num1+num2)); _______________________________
iii) System.out.println((int)num1+(int)num2); _______________________________
Page No. 2
6. Assign the value of (1.732) to a variable with the requisite data type.
___________________________________________________________________________
7. Write down the data type of the following
i. A fractional number : ______________________________________
ii. long integer : ______________________________________
iii. Integer : ______________________________________
iv. A special character : ______________________________________
8. Write Java statements to declare the following
i. A float variable : ______________________________________
ii. A char variable, & assign 0 to it: ______________________________________
iii. A Boolean variable & assign false to it:____________________________________
iv. A double variable, & assign the result of the expression 15/5*6.2 to it
_____________________________________________________________________
9. Which of the following assignments are valid?
i. long number = 45,000 : _______________________________________
ii. boolean a= 1 : _______________________________________
iii. short y+5=20 : _______________________________________
iv. int p/10=q : _______________________________________
v. byte e1==6 : _______________________________________
vi. int no=+1.5 : _______________________________________
vii. char c1= “/0” : _______________________________________
10. Identify the literal elements of the following
i. 43 : _____________________________________________________
ii. ‘b’ : _____________________________________________________
iii. 65.567 : _____________________________________________________
iv. “JAVA” : _____________________________________________________
1. Evaluate the following expressions
i) int a=5;
a= a++ + ++ a;
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
ii) int p=8, q=12;
p=p++ + --q +(++p + --q) + p++
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
iii) int x=9, y=4;
Page No. 3
x=--x+--x+--x+ ++y + y-- - --y;
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
iv) int m=5, n=10;
m=(++m/2)+(m++%n)+(--n + --n);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
v) int t=8;
t= --t + ++t - --t+ --t + ++t + t++;
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
vi) Evaluate the following expression, if the value of the variable p=6,m=15, and r=9;
w=p*(m++/3)+p+(--r+r++);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
vii) int s=7, t=11;
s=s++ - ++t +s;
System.out.println(“s=”+s); _________________________________________
System.out.println(“j=”+j); _________________________________________
viii) What is the result produced by 2-10*3+100/11? Show the steps.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
ix) Write the output for the given statement.
int z=13,y=10,a=100;
a/=z++ + ++z *(--y – y--)%3+z++ - ++y;
System.out.println(a);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
x) Solve the following and write the value of ‘a’ when printed.
int a=0,b=30,c=40;
a+=--b + c++ +b*c + ++a%5;
______________________________________________________________________________
______________________________________________________________________________
Page No. 4
______________________________________________________________________________
xi) Predict the output of the following
int mrk_obt=256, tot=500;
double per=mrk_obt/tot*100.0;
System.out.println(“The Percentage is”+per+ “%”);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xii) Write the java expression for the following
m=uv/(u+v)
_________________________________________________________________________
t=a+(cd)3
_________________________________________________________________________
xiii) Rewrite the following snippet using ternary operator.
if(income>200000)
tax=10
else
if(income>100000)
tax=5;
else
tax=0;
_________________________________________________________________________
xiv) Write the corresponding expression of the following mathematical operation:
z=x3+y3 - xy/z
_________________________________________________________________________
xv) If a=4, b=3; find the value of c = a++ * 6+ ++b * 5 +10;
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xvi) If int p=7 and int q=2 output the values of p and q after execution of
p*=q;
p=_________________________
q=_________________________
q=p+p/q
p=_________________________
q=_________________________
xvii) Predict the output of the following statement
System.out.println(!((7>5)||(13<1))&&(11>5));
__________________________________________________________________________
___________________________________________________________________________
xx) Write the output for the given statement.
int z=13,y=10,a=100;
a/=z++ + ++z *(--y – y--)%3+z++ - ++y;
System.out.println(a);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxi) Evaluate the given expression int p=7,q=9, r=11
p+=(--p+5)*(q++)+(--r/2);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxii) Write the output of the following statements
int num = 30;
System.out.println(( num > 5 ? ( num <= 10 ? 100 : 200 ) : 500 ));
________________________________________________________________________________
xxiii) Evaluate the following expression where a=2, b=5, and c=7 here a, b, c are of integer
type a=++a * b--/(a++)%20+(++c)
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
_________________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page No. 6
xxvi) Write a corresponding Java expression for the mathematical expression:
z=(sin x + cos x)+ y3*t
___________________________________________________________________________
xxvii) Write the following in the shorthand form? A=A/15;
___________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxix) Write the output of the given statements
System.out.println(1.0/2*10*10); _________________________
___________________________________________________________________________
xxxi) Give the output of the following expression
a+=a++ + ++a + --a + --a; when a=7
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxxii) Evaluate the given expression int p=9,q=3, r=6
p/=(--p+5)*(q++)+(--r/2);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxxiii) Write the output when
int cash=1100, bal=350;
int sum=cash+bal>1850?4000:2500;
System.out.println(sum);
______________________________________________________________________________
xxxiv) Write the following expression in the Shorthand form.
f=f*65
______________________________________________________________________________
xxxv) Rewrite the following snippet using ternary operator.
if(a>b)
Page No. 7
{
if(a>c)
max=a;
else
max=c;
}
else
{
if(b>c)
max=b;
else
max=c;
}
1. Study the following snippets and answer the following
i) System.out.println(Math.abs(Math.ceil(-6.7)));
______________________________________________________________________________
ii) System.out.println(Math.sqrt(Math.max(5,Math.floor(9.9))));
______________________________________________________________________________
iii) System.out.println(Math.max(Math.ceil(8.3),Math.floor(8.3)));
______________________________________________________________________________
iv) System.out.println(Math.pow(Math.abs(-2),Math.rint(3.8)));
______________________________________________________________________________
v) System.out.println(Math.ceil(-28.25));
______________________________________________________________________________
vi) System.out.println(Math.min(Math.max(60,70),5));
______________________________________________________________________________
______________________________________________________________________________
Page No. 8
System.out.println(n);
______________________________________________________________________________
ix) System.out.println(Math.pow((Math.floor(3.80)),(Math.ceil(4.59))));
_______________________________________________________________________________
x) System.out.println(Math.abs(++t* -6)) if t=4
_______________________________________________________________________________
xi) Predict the return data type of the following
float m;
System.out.println(m/3*(Math.pow(4,3));
________________________________________________________________________________
xii) System.out.println( 1/2 +4/5);
_______________________________________________________________________________
xiii) Write all the possible values of n for the given function.
int n=(int)((Math.random( )*6)+1);
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
ii) int x=10,y=20;
if(x==y)
System.out.println(x+" "+y);
_______________________________________________________________________________
_______________________________________________________________________________
_______________________________________________________________________________
v) int i=65;
char j='A';
if(i==j)
System.out.println("Java is WOW");
else
System.out.println("Java is Headache");
_______________________________________________________________________________
vi) Spot the error if any in the program else write the output.
int x=100,y=0,z=0;
if(x>50)
y=25;
z=30;
else
y=80;
z=90;
System.out.println(x+ “,” +y+ “,”+z);
_____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
_______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xi) Write the output of the following
int a=1,b=2,c=3;
switch(p)
{
case 1: a++;
case 2: ++b;
break;
case 3: c--;
}
System.out.println(a+ “,”+b+ “,”+c);
Write the output when p=1 and p=3
p=1__________________________________________________________________________
p=3__________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page No. 11
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xiii) What output will the following code fragment produce?
char opn= ‘b’;
switch(opn)
{
case ‘a’:
System.out.println(“Java is platform independent”);
case ‘b’:
System.out.println(“Java is Object Oriented”);
case ‘c’:
System.out.println(“Java is Robust and Secure”);
default:
System.out.println(“Wrong Input”);
}
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
___________________________________________________________________________
xiv) Write a block of code using switch case to check whether value in variable ‘a’ is odd or
even.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xv) Write the following statement using switch case construct.
if(a==1)
{b+=10;
System.out.println(b); }
else if(a==2)
{ b-=10;
System.out.println(b); }
else
{ b*=a;
System.out.println(b); }
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page No. 12
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xvi) Write a code to print whether the given character (ch) is a vowel or not using switch case
statement
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xvii) Rewrite the following using if else statements:
i. Status =(Age==18? “Adult” : “Child”;
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
i) Give the output of the given program
int z=18;
for(int x=1;x<=z;x++)
{
if(z%x==0)
System.out.println(x);
}
______________________________________________________________________________
______________________________________________________________________________
Write what mathematical operation in carry.
______________________________________________________________________________
ii) Analyze the following program segment and determine
int z=148;
while(10>9)
{
if(z<139)
break;
System.out.println(“Computer”+z);
z=z-3;
}
System.out.println(z);
How many times the loop will get executed.
____________________________________________________________________________
Write the output
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
iii) Observe the following snippet and answer the following questions
Page No. 14
int j,k=5;
while(k>=1)
{
j=1;
while(j<=k)
{
System.out.print(j);
j++;
}
System.out.println( );
k--;
}
Rewrite it using for loop.
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
____________________________________________________________________________
iv) Analyze the following program segment and determine
int a=100;
while (true)
{
if(a<90)
break;
System.out.println("Wisdom"+a);
a=a-2;
}
System.out.println(a);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page No. 15
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
v) Give the output.
void test(int a, int b)
{
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
System.out.println(a);
}
If a=4 and b=16 are passed to the function.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
vi) What will be the output of the following code
int i= 0, a=0;,b=0,c=0;
while(i<=5)
{
switch(i++)
{
case 1: a++;
case 2:
case 3: b++;
case 4:
default : c++;
}
}
System.out.println(a+ “ “ + b+ “ “ + c);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
vii) Predict the output of the given statements or mention syntax error if there is?
1. void main( )
{
int i=1;
while(i<=10);
{
System.out.print(i+ “,”);
i++;
}
}
Page No. 16
______________________________________________________________________________
______________________________________________________________________________
2. float x=1.1f;
while(x==1.1f)
{
System.out.println(x+",");
x=x-0.1f;
}
______________________________________________________________________________
______________________________________________________________________________
3. int count =0,sum=0;
while(count!=10)
{
count=1;
sum=sum+count;
count++;
}
System.out.println(count);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
viii) What output will the following code produce?
for(int i=1,j=2; i<=8; i++, j--)
System.out.println(i++*j);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
ix) Analyze the following program segment and determine
int x=4,y=0;
while(x>=0)
{
x--;
y++;
if(x==y)
continue;
else
System.out.println(“Value of x is”+x+ “Value of y is”+y);
}
__________________________________________________________________________
______________________________________________________________________________
Page No. 17
______________________________________________________________________________
______________________________________________________________________________
x) Write the output of the following
int i, j ;
for ( i = 1 ; i <= 2 ; i++ )
{
for ( j = 1 ; j <= 2 ; j++ )
{
if ( i == j )
continue ;
System.out.println(i+" "+j) ;
}
}
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xi) Write the output of the given statements
while ( 'a' < 'b' )
System.out.println("\nmalyalam is a palindrome") ;
______________________________________________________________________________
______________________________________________________________________________
xii) Write the output and justify your answer
int a=1;
for(;a<=10;a++);
System.out.println(a);
______________________________________________________________________________
______________________________________________________________________________
xiii) Write the output of the given snippet
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(“*”);
}
System.out.print(“”);
}
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
Page No. 18
______________________________________________________________________________
xiv) Spot the error else predict the output of the following snippet.
void test(int n)
{
int i=1;
while(i<=n)
{
System.out.println(i);
break;
i++;
}}
If the value of ‘n’ supplied is 5.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xv) Rewrite the following code using for loop.
int a=5; int b=25;
while(true)
{
if(a>b)
break;
System.out.println(a+"\t"+b);
a+=5;
b-=5;
}
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xvi) Study the following loop and answer the questions that follows
int i,j,k;
for(i=0;i<2;i++)
{
Page No. 19
for(j=0;j<=2;j++)
{
for(k=0;k<1;k++)
System.out.println(i+ “,”+j+ “,”+k);
}
}
How many times the print statements will get execute?
_________________________________________________________________________
Write its output.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xvii) Write the output of the following statements are executed.
for(int i=1;i<=5;i++)
{
for(int j=5;j>=i;j--)
System.out.print("*");
for(int x=1;x<=i;x++)
System.out.print(i);
System.out.println();
}
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xviii) Predict the output of the following if the value of variable ‘n’ is 7
int i=1;
while(i++<=10)
System.out.println(n+"x"+i+"="+n*i++);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xix) Write the output when the following print statement is executed
int num=2080, tot=0;
Page No. 20
while(num>0)
{ int l=num%10;
tot=tot*10+l;
num=num/10;}
System.out.println(tot);
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
xxi) What will be the result (true or false) of following two expression if i=10 initially.
++i<=10
______________________________________________________________________________
i++<=10
______________________________________________________________________________
xxii) Write a statement for each of the following
i) Store a number 275 as a String
ii) Convert the String to a numeric value
iii) Add it to the existing total to 1000 to update the total.
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
i) Write the output of the following
1. System.out.println(Character.isUpperCase(‘g’));
_____________________________________________________________________________
2. System.out.println(Character.toUpperCase(‘H’));
______________________________________________________________________________
3. System.out.println(“Computer Application”.lastIndexOf(‘C’));
______________________________________________________________________________
______________________________________________________________________________
iv) String b= “COMPUTER’s WORK SHOP”;
System.out.println(b.toUpperCase());
______________________________________________________________________________
v) Write the output of the following snippet
String x= “Applications”;
String y= “Computer”;
System.out.println(x.indexOf(x.charAt(2)));
______________________________________________________________________________
System.out.println(y.substring(0,3)+x.substring(7));
______________________________________________________________________________
System.out.println((x.length()>y.length())?(5>3):(4<33));
______________________________________________________________________________
System.out.println(x.charAt("Kareena".compareTo("Karan")));
______________________________________________________________________________
______________________________________________________________________________
System.out.println(a.length()+b.length());
______________________________________________________________________________
System.out.println(b.charAt(2));
______________________________________________________________________________
System.out.println(a.equals(b));
______________________________________________________________________________
______________________________________________________________________________
System.out.println(Character.toUpperCase(‘H’));
______________________________________________________________________________
viii) Write the output of the following
String str=”Rajesh”;
System.out.println(str.replace(‘j’ , ‘k’);
Page No. 22
______________________________________________________________________________
ix) String x= “Computer”;
System.out.println(x.indexOf(x.charAt(4)));
______________________________________________________________________________
x) Write a java statement for the following.
To display the 4th character of the string “computer”
______________________________________________________________________________
xi) Write the output of the following functions
“THAN”.compareTo(“THEN”)
______________________________________________________________________________
“computer”.startsWith(“Comp”)
______________________________________________________________________________
xii) Write the output of the following
1. (int)(“Scholar”.charAt(2));
______________________________________________________________________________
2. “MISSISSIPPI”.lastIndexOf(‘S’);
______________________________________________________________________________
3. “kumarvivek”.substring(3,4)
______________________________________________________________________________
______________________________________________________________________________
2. System.out.println("computer".toUpperCase().replace("TE","te"));
______________________________________________________________________________
xiv) Give the output of the following statements
String s= “There”,w=”TheRE”, x=s;
System.out.println(s.equals(x));
______________________________________________________________________________
System.out.println(s==x);
______________________________________________________________________________
System.out.println(w.compareTo(s));
______________________________________________________________________________
System.out.println(s.toUpperCase( )==w.toUpperCase( ));
______________________________________________________________________________
System.out.println(w.endsWith(“eRE”));
______________________________________________________________________________
System.out.println(s.indexOf(‘e’));
______________________________________________________________________________
xv) What output will the following statement produce?
System.out.println("BLUEJ".length()> "bluej".length()?true:false);
Page No. 23
______________________________________________________________________________
System.out.println(“Grade X Students”.charAt(5)==‘X’);
______________________________________________________________________________
System.out.println(“Computer”.compareTo(“Commercial”));
______________________________________________________________________________
xvi) Study the snippet given below and answer the following questions.
void test(String m, String n)
{
if(m.compareTo(n)>0)
System.out.println(m.compareTo(n));
else
System.out.println(n.compareTo(m));
}
1. If “AMIT” and “amit” are passed to the function.
______________________________________________________________________________
2. If “15 August 1947” and “August 15 2010” are passed to the function.
______________________________________________________________________________
xvii) Write two ways to concatenate the following two strings together to get the
String “computer”
String fst= “uter”;
String lst= “comp”;
______________________________________________________________________________
______________________________________________________________________________
xviii) Predict the output
System.out.println("Wisdom High".length()==("International".substring(2)).length());
______________________________________________________________________________
System.out.println("Java applet".endsWith("applet".substring(0,4)));
______________________________________________________________________________
xix) Write the output of the following
System.out.println("malayalam".substring(3,8).lastIndexOf('a'));
______________________________________________________________________________
System.out.println("computer".toUpperCase().replace("TE","te"));
______________________________________________________________________________
xx) Predict the output of the given snippet.
String x= “Computer”;
String y= “Papaya”;
System.out.println(y.indexOf(x.charAt(3));
______________________________________________________________________________
______________________________________________________________________________
System.out.println(mantissa);
______________________________________________________________________________
xxii) Write the output for the print statement if the initial value of
String na= “Hi How Is Harry”;
na=na.toUpperCase();
String fi=na.charAt(0)+".";
int a=na.indexOf(' ');
fi=fi+na.charAt(a+1)+".";
int b=na.lastIndexOf(' ');
fi=fi+na.substring(b+1);
System.out.println(fi);
______________________________________________________________________________
xxiii) What will be the output for the following program segment?
String s=“Computer”;
String t= new String (“Applications”);
System.out.println (s.charAt (t.indexOf (‘i’)));
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
System.out.println (s.equals (t));
______________________________________________________________________________
______________________________________________________________________________
xxv) Write the output for the following statement
System.out.println((“Tata”.indexOf(‘a’))+ “\t” +(“Tata”.lastIndexOf(‘x’)));
______________________________________________________________________________
Page No. 25
xxvi) Write the output of the following
String f1="Tourism Australia";
String f2="Krafty";
String a="Cricket World Cup";
System.out.println(f1.charAt(f2.indexOf('t'))+f2.substring(2,4));
______________________________________________________________________________
System.out.println(Character.toUpperCase(f2.lastIndexOf('a')));
______________________________________________________________________________
System.out.println(a.indexOf('c',f2.length()));
______________________________________________________________________________
System.out.println(a.replace((char)67,f2.charAt(0)));
______________________________________________________________________________
System.out.println(Math.ceil(Math.min(-9.9,9.9)));
______________________________________________________________________________
String f3=f1;
for(int i=1;i<=3;i++)
f3=f3+" ";
System.out.println(f1.compareTo(f3));
______________________________________________________________________________
Predict the Output
i) To display 100th element of the array arr[ ]
____________________________________________________________________________________
ii) Correct the error in the following program segment and rewrite it:
Int n[ ]=(3,6,9,12,15);
for(int i=0;i<=5;i++)
System.out.println(“The value is” +n[j]);
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
iii) Predict the output of the following snippet
int a[ ]= new int [5];
a[0]=4; a[4]=8; a[3]=12; a[1]=3; a[2]=7;
System.out.println(a[2+1]);
____________________________________________________________________________________
____________________________________________________________________________________
Page No. 26
____________________________________________________________________________________
v) int a[ ]={5,7,9,11,13};
a[0]=9;
a[3]=a[4];
int c=a[0]+a[3]+2+0;
System.out.println(c);
____________________________________________________________________________________
vi) int a[ ]={5,1,15,20,25};
int i=++a[1];
int j=a[++1];
System.out.println(“The value of i is”+i);
System.out.println(“The value of j is”+j);
____________________________________________________________________________________
____________________________________________________________________________________
vii) Declare and Initialize an array of float type with the following values
3.2,5.7,2.9,7,4,6.6
____________________________________________________________________________________
viii) The following numbers are required to be sorted in ascending order using selection sort
technique. Write the list as it will appear at the end of the process of inner loop. (Step 1 is
being done for you) Numbers are 89, 20, 31, 56, 22, 64, 48
Step 1. 20, 89, 31, 56, 22, 64, 48
Step 2. ______________________
Step 3. _______________________
Step 4. _______________________
Step 5. _______________________
Step 6. _______________________
Step 7. _______________________
ix) Write the output of the following code
int num[ ]={2,5,9,7,11,4,1};
num[1]=num[3];
num[2]=num[5];
num[3]=13;
num[4]=num[0];
num[0]=num[5+1];
num[5]=num[5]+num[1];
for(int i=0;i<num.length;i++)
System.out.print(num[i]+ “,”);
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
____________________________________________________________________________________
x) Write the output of the following code
char c[ ]={‘c’, ‘o’, ‘m’, ‘p’, ‘u’, ‘t’, ‘e’, ‘r’};
for(int i=0;i<c.length;i++)
System.out.print((char)--c[i]);
____________________________________________________________________________________
xi) Write the output of the following code:
Page No. 27
void display ( )
{
int p[ ]={1,11,111,1111,11111};
for(int i=(p.length -1);i>=0;i--)
System.out.println(p[i]);
}
____________________________________________________________________________________
____________________________________________________________________________________
i. Correct the error in the following program segment and rewrite it:
public void Add(int a,b)
{
int c=a+b;
return(c);
}
_____________________________________________________________________________________
_____________________________________________________________________________________
____________________________________________________________________________________
ii. Study the given function and answer the questions that follows it.
int function(int a, int b)
{
int sm,la,ans;
if(a<b)
{
sm=a;
la=b;
}
else
{
sm=b;
la=a;
}
ans=la;
while(ans%sm!=0)
ans+=la;
return(ans);
}
What value will the function return if 7 and 5, are supplied to the function.
_____________________________________________________________________________________
What is function ( ) doing?
_____________________________________________________________________________________
iii. Does the following program is having any error, if no, write the output.
public class trial
{
public static void main( )
{
trial func = new trial( );
double x=func.first(2,8);
double y=func.first(16);
System.out.println(“The value of x is”+x+ “The value of y is”+y);
}
Page No. 28
public double first( int x, int y)
{
return(Math.pow(x,y));
}
public double first (int x)
{
return (Math.sqrt(x));
}
}
_____________________________________________________________________________________
_____________________________________________________________________________________
iv. Study the following program and answer the question below.
class q3
{
static void main( )
{
q3 paper = new q3( );
int m[ ]={15,13,11,9,7};
int k=paper.pro(m[3]);
System.out.println(“The value of k in the main function is”+k);
}
int pro(int x)
{
x=x+2;
System.out.println(“The value of x in the pro function is”+x);
return(x);
}
}
Is the program having an error? If yes, then after rectifying the error answer the following questions
_____________________________________________________________________________________
What is the value of k in the main function?
_____________________________________________________________________________________
What is the value of x in the pro function?
_____________________________________________________________________________________
Name this style of passing the value to the function.
_____________________________________________________________________________________
What is the disadvantage of this style?
_____________________________________________________________________________________
Name the data type that can be passed by this style.
_____________________________________________________________________________________
v. Study the snippet given below and answer the following questions.
int perform(int num)
{
int r=0;
do
{
int d=num%10;
r=r*10+d;
num=num/10;
}
while (num>0);
Page No. 29
return(r);
}
What value will the function return if 2008 is passed to the function?
_____________________________________________________________________________________
What mathematical process is the function doing?
_____________________________________________________________________________________
vi. For the given function write down the main function which calls it:
int square (int a)
{
return(a*a);
}
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
vii. Consider the following code:
class Check
{
public static void main( )
{
int x=10,y=20;
System.out.println(data(x,y));
}
public int data(int a, int b)
{
return(a*b);
}}
Will it compile? YES or NO. Give reason. Also rectify the code if it will give error.
_____________________________________________________________________________________
viii. Predict the output when the main function is executed.
class Main
{
Main()
{ calculate();
System.out.print("Good Movie "); }
void calculate()
{ show();
System.out.print(" It is "); }
void show()
{ System.out.print("Rating is 3 stars ");
display();
System.out.print(" Smile "); }
void display()
{ System.out.print("Thank you"); }
public static void main()
{ Main func=new Main(); }}
_____________________________________________________________________________________
_____________________________________________________________________________________
Page No. 30
_____________________________________________________________________________________
ix. The following program prints the uppercase letters. The functions are nested. Fill in the
blanks so that the program works correctly.
class Fill
{
void convert (int i) //receives ascii code
{char d=____________ //convert ascii code to character
System.out.println(_______) // prints equivalent character
}
void callConvert( )
{
for(int i=65;i<=__;__) //generate ascii code of uppercase letters
{
_____________ //calls the method
}}}
x. Write a function with three parameters of type int and contain the code to find the biggest of
the three. The value of the biggest parameter should be returned as the value of the
function.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
1. Study the following program and answer the question below.
class gradeX
{
String na;
int a,b,c;
gradeX( )
{
a=5;
b=90;
na= “Wisdom High”;
}
void gradeIX( )
{
int x=1;
for(int i=1;i<=a;i++)
x=x*i;
c=x;
na=na+ “International School”;
}
void gradeXI( )
{
System.out.println(“The answer is”+c);
System.out.println(“The answer is”+na);
}
}
Does the program have any error? If yes than after rectifying answer the following questions.
_____________________________________________________________________________________
Name all the instance variables of the program.
_____________________________________________________________________________________
Name all the local variables of the program.
Page No. 31
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
State the reason why ‘x’ cannot be printed in member function gradeXI( ).
_____________________________________________________________________________________
_____________________________________________________________________________________
What is the out of the program? (assuming gradeIX( ) is executed first and then grade XI ( )).
_____________________________________________________________________________________
_____________________________________________________________________________________
Name the variables that are common to all objects of the class.
_____________________________________________________________________________________
3. Study the given class and name the question that follows it.
class Class
{
int a=5;
double S=52.33;
static String t="Static";
void input()
{
int sum=0;
double tot=5;
}
private display()
{
System.out.println(S);
System.out.println(t);
}
public void Class()
{
S=0;
t="";
}
Page No. 32
}
Name all the instance variable of the class.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
4. Study the following program and answer the questions that follow it.
public class conover
{
int x,y;
String na;
boolean t;
double z;
conover()
{
x=35;
t=true;
}
conover(int a,String b)
{
y=a;
na=b;
}
void add()
{
z=x+y;
na=na+"false";
}
void display()
{
System.out.println(x+", "+y);
System.out.println(t);
System.out.println(z);
System.out.println(na);
}
static void main()
{
Page No. 33
conover f=new conover();
conover ff=new conover(6,"true");
f.add();
f.display();
ff.display();}}
Write the output when main( ) function is executed.
_____________________________________________________________________________________
Assuming all the instant variable are changed to static, now write the output when main( ) function
is executed.
_____________________________________________________________________________________
Name the concept of Java implement in this program, give reason.
_____________________________________________________________________________________
5. Can a program having a class can be executed error free without a constructor? Justify.
_____________________________________________________________________________________
6. Create an object square of class Figure using parameterized constructor. It has two instance
variable namely name (of String type) and area (of int type)
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
8. public class FirstPre
{ void add()
{
e=a+b;
c=c+"false";
}
void display()
{
System.out.println(a+", "+b);
System.out.println(c);
System.out.println(d);
System.out.println(e);
}
Page No. 34
int a,b;
String c;
boolean d;
double e;
FirstPre()
{
b=150;
d=true;
}
FirstPre(int a,String b)
{
this.a=a;
c=b;
}
static void ControlRoom()
{
FirstPre f=new FirstPre();
FirstPreff=new FirstPre(6,"true");
f.add();
f.display();
ff.display();
}
}
Write the output when ControlRoom( ) function is executed.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Assuming all the instant variable are changed to static, now write the output when ControlRoom( )
function is executed.
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
_____________________________________________________________________________________
Name any two OOP principles that is being implement in this program.
_____________________________________________________________________________________
_____________________________________________________________________________________
Page No. 35