Class ix 50 Short Questions
Class ix 50 Short Questions
2. Find the error in the following code snippet 3. Rewrite the following using ternary operator:
and correct them: if(p>=430)
boolean true=a; k=p*5/100;
if(false) else
System.out.println(“Nothing in here”); k=p*10/100;
else
System.out.println(“correct this mistake”);
4. Identify the following as valid or invalid identifier name . State reasons. I) _123 ii) break iii) T$ iv) var.1
5.
Write the expression for the absolute value of
6. What a java statement to:
i) create an object mp3 of class Music ii) import all the classes of the package named simple.
7. What will the following functions return when executed: i) Math.max(-7, Math.min(-2,-9)) ii) Math.ceil(32.17)
8. Write the memory capacity (storage size) of short and float data type in bytes
9. Identify and name the following tokens: (i) public (ii) ‘a’ (iii) == (iv) { }
10. Write a Java expression for the following: |x²+2xy|
11. If the value of basic = 1500, what will be the value of tax after the following statement is executed
tax = basic > 1200 ? 200 : 100
12. Give the Output of the following: Math.sqrt(Math.max(9,16))
13. Evaluate the following expression if the value of x=2,y=3 and z=1.v = x + – -z + y++ + y
14. Give the output of the 15. Rewrite the following using 16. Write the output:
following program ternary operator: int y=6;
segment and also mention if(bill > 10000) for(; y<=20;y+=2)
how many times the loop discount = bill * 10.0 / 100; System.out.println(y);
is executed: else Systme.out.println(y);
int i; discount = bill * 5.0 / 100;
for(i = 5; i > 10; i++)
System.out.println(i);
System.out.println(i * 4);
17. Convert the following if else if 18. Find out error(if any) 19. Find the output:
construct into switch case: class test char a=’e’;
if(var == 1) { int b=12;
System.out.println("good"); Public static main(); int c=40;
else if(var == 2) { char d=’d’;
System.out.println("better"); Int a=10; System.out.println(a+d);
else if(var == 3) system.out.printline(“Values a is” a); System.out.println(b+c);
System.out.println("best"); }
else }
System.out.println("invalid");
20. Give the output of the following: (i) Math.floor(-4.7) (ii) Math.ceil(3.4) + Math.pow(2, 3)
21. What is the value of y after evaluating the expression given below? y += ++y + y– + –y; when int y = 8.
22. Write a Java expression for the following: √(3x + x²) / (a + b)
23. What will be output of the 24. How many times will the 25. Convert the following if else to switch
following program following loop execute? What char x; int m=0;
statement? value will be returned? if(x==’a’)
public static void main() int x=2,y=50; m=m+1;
{ do if(x==’b’)
int a; { m=m+2;
a=25-4-4; ++x; if(x==’c’)
System.out.println(a); y-=x++; m=m+3;
} }
while(x<=10);
return y;
26. Write the java expression for 3/8 √b -c3
2
27 What is difference between a pure and mixed expression.
28. Analyze the following program 29. Write the output : 30. Write the output
segment and determine how int num=12345,n=0; for(i=9;i>=1;i=i-2)
many times the body of loop will int t[]=new int[5]; {
be executed and that will be the while(num>0) for(j=1;j<=I;j=j+2)
output of the program segment. { {
int p=200; t[n++]=n%10; System.out.print(j+” “);
while(true) num/=10; }
{ System.out.println(t[n- System.out.println();
if(p<100) 1]); }
break; }
P=p-20;
}
System.out.println(p);
31. What are the types of casting shown by the following examples:-
i.double pie=3.14; int rad=(int) pie; ii. int x=7892; long y=x;
32. Rewrite the following segment using if .. else statement String grade=(marks>=85)?”A”: (marks>=80)?”B”:”C”;
33. State escape sequences for vertical tab and new line feed.
34. While loop to for loop 35. What do you mean by “out of 36. convert the following do-while
int ctr,n=0; bound exception”? loop into for loop
while(ctr<=20) char ch=’F’; int i=1; int d=5;
System.out.println(n+” “); int m=ch++; do
n++; m=m+5; {
ctr++; System.out.println(m+” “+ch); d=82;
System.out.println(d);
37. The statement is c+=(a>0 && a<=10)!++a:a/b; i++;
What is the value of c? Show the steps. }
38. Predict the output: if n=15 find the output i) ++n*2 ii) n++ *2 while(i<=5);
39. State the output of the following program when x=9 40. void output
and x=10 {
if(x++==11) double v;
System.out.println(“Result is 11”); v=Math.sqrt(Math.abs(-64));
else if(++x==10) System.out.println(“The output is=”+v);
System.out.println(Result is 10); }
else
System.out.println(“Result is neither 10 not 11);
41. Find the value of ‘a’ and ‘b’ i) a=Math.ceil(67.87); ii) b=Math.floor(22.75);
42. Rewrite the following condition without using logical operators if(a>b || a>c) System.out.println(a);
43. What is the output of the following:
String a=”Java is programming language \n developed by \t\’james Gosling\’”; System.out.println(n);
44. State the type of errors if any in the following statement: i) switch(n>2) ii) System.out.println(100/0);
45. What are default values of the primitive data type int and float?
46. Rewrite the following program segment using if else statements String grade=(mark>=90?”A”:(mark>=80)?”B”:”C”;
47. What is precedence of operators? Arrange the following operations in their order of precedence from higher to
lower i) == ii) () iii) >= iv) %
48. Identify the following as valid variable names. State the reason i) _345 ii) c*345 iii) name$ iv) student
49. Write the prototype of a function result which receives a character x and an integer y and return true and false.
50. In the following statements assume a =50, b=10 and c=20;