The document consists of a series of programming questions and tasks primarily focused on Java programming concepts, including operators, loops, method prototypes, and data types. It includes evaluations of expressions, code outputs, and conversions between different control structures. The questions cover a wide range of topics, from basic syntax to more complex logic and mathematical operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
39 views2 pages
60 Short Questions
The document consists of a series of programming questions and tasks primarily focused on Java programming concepts, including operators, loops, method prototypes, and data types. It includes evaluations of expressions, code outputs, and conversions between different control structures. The questions cover a wide range of topics, from basic syntax to more complex logic and mathematical operations.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
1. A mechanism where one class acquires the 24.
Evaluate the following if the value of x=7, y=5
properties of another class 25. Evaluate the following if the value of x=7, y=5 x+=x++ 2. Identify the type of operator &&: + x + ++y 3. The Scanner class method used to accept words with 26. Write the output: System.out.println(''A picture is space: worth \t \''A thousand words.\'' ''); 4. The keyword used to call package in the program: 27. Give the output of the following program segment 5. What value will Math.sqrt (Math.ceil (15.3)) return? and mention how many times the loop will execute: 6. The absence of which statement leads to fall through int k; situation in switch case statement? for ( k = 5 ; k < = 20 ; k + = 7 ) 7. State the type of loop in the given program segment: if ( k% 6==0 ) for (int i = 5; i ! = 0; i - = 2) System.out.println(i); continue; 8. Write a method prototype name check() which takes System.out.println ( k ); an integer argument and returns a char: 28. Rewrite the following program segment using logical 9. The number of values that a method can return is: operators: 10. Predict the output of the following code snippet: if ( x > 5 ) String P = "20", Q ="22"; int a = Integer.parseInt(P); if ( x > y ) int b = Integer.valueOf(Q); System.out.println (x+y); System.out.println(a+""+b); 29. Convert the following if else if construct into switch 11. int x = (int) 32.8; is an example of _____ typecasting. case: 12. The code obtained after compilation is known as: if (ch== 'c' || ch=='C') 13. Missing a semicolon in a statement is what type of System.out . print(''COMPUTER''); error? else if (ch== 'h' || ch=='H') 14. Consider the following program segment and select System.out . print(''HINDI''); the output of the same when n = 10 : switch(n) {case else 10 : System.out.println(n*2); case 4 : System.out . print(''PHYSICAL EDUCATION''); System.out.println(n*4); break; default : 30. Give the output of the following: System.out.println(n); } (i) Math.pow (36,0.5) + Math.cbrt (125) 15. A method which does not modify the value of (ii) Math.ceil (4.2 ) + Math.floor (7.9) variables is termed as: 31. Rewrite the following using ternary operator: 16. When an object of a Wrapper class is converted to its if(n1>n2) corresponding primitive data type, it is called r = true; as_____. else r = false; 17. The number of bits occupied by the value ‘a’ are: 32. Give the output of the following code: 18. Write the Java expression for (𝑎 + 𝑏)x String P = "20", Q ="19"; 19. Evaluate the expression when the value of x = 4: x * int a = Integer.parseInt(P); int b = Integer.valueOf(Q); = - - x + x++ + x System.out.println(a+""+b); 20. Convert the following do…while loop to for loop: int 33. State the data type and value of res after the x=10; do {x– –; System.out.print(x); }while (x>=1); following is executed: 21. Rewrite the following code using the if-else : int m= char ch = '9'; 400; double ch = (m>300) ? (m / 10.0) * 2: (m / 20.0) res= Character.isDigit(ch); - 2; 34. Write a Java expression for the following: 22. Give the output of the following program segment: | x2+2xy | int n = 4279; int d; 35. If the value of basic=1500, what will be the value of while(n>0) tax after the following {d=n%10; statement is executed? tax = basic>1200 ? 200 :100; System.out.println(d); n=n/100; } 36. Give the output of following code and mention how 23. Write the value of n after execution: char ch ='d'; int many times the loop will execute? n = ch + 5; int i; for( i=5 ; i>=1 ;i--) int i = 1; int d=5; {if(i%2 ==1) do {d=d*2; continue; System.out.println(d); System.out.print( i+ '' '');} i++ ; } while ( i<=5); 37. Give the output of the following: 51. What are the values stored in variables r1 and r2: Math.sqrt(Math.max(9,16)) (i) double r1 = Math.abs(Math.min(-2.83, -5.83)); (ii) 38. Evaluate the following expression if the value of x=2, double r2 = Math.sqrt(Math.floor(16.3)); y=3 and z=1. v=x+ --z+ y++ +y 52. Give the output of the following code: 39. Write a Java expression for the following: String A ="26", B="100"; (√3x + x2)/(a + b) String D=A+B+"200"; 40. Give the output of the following: (i) Math.floor (-4.7) int x= Integer.parseInt(A); int y = Integer.parseInt(B); (ii) Math.ceil(3.4) + Math.pow(2, 3) int d = x+y; 41. What is the value of y after evaluating the expression System.out.println("Result 1 = "+D); given below? y+= ++y + y-- + -- y; when int y=8 System.out.println("Result 2 = " +d); 42. Write the output for the following: 53. Analyze the given program segment and answer the System.out.println("Incredible"+"\n"+"world"); following questions: 43. Convert the following if else if construct into switch for(int i=3;i<=4;i++ ) { if( var==1) for(int j=2;j<i;j++ ) { System.out.println("good"); System.out.print("" ); } else if(var==2) System.out.println("WIN" ); } System.out.println("better"); (i) How many times does the inner loop execute? else if(var==3) (ii) Write the output of the program segment. System.out.println("best"); 54. What will be the output of the following code? else System.out.println("invalid"); float x = 7.87; System.out.println(Math.ceil(x); 44. Rewrite the following using ternary operator: System.out.println(Math.floor(x); if (bill >10000 ) 55. What will be the output of the following code? discount = bill * 10.0/100; int a = 0; else discount = bill * 5.0/100; if(a>0 && a<20) 45. Give the output after correcting error. a++; for (int i = 5 ; i > 10; i ++ ) else a-- ; System.out.println( i ); System.out.println(a); System.out.println( i * 4 ); 56. What will be the output of the following code? 46. Give the output of the following program segment int a= 5, b = 2,c; and also mention the number if (a>b || a ! = b) of times the loop is executed: c = ++a+--b; int a,b; System.out.print(c+ “ ”+a+ “ ”+b); for (a = 6, b = 4; a <= 24; a = a + 6) 57. What will be the output of the following code? { int i = 1; if (a%b ==0) while(i++<=1) break; { i++; System.out.print(i + “ ” ); } } System.out.print(i); System.out.println(a); 58. What is the result produced by 2 – 10*3 + 100/11? 47. Write the output: Show the steps. char ch = 'F'; int m = ch; 59. int x =20, y = 10, z;What is the value of z m=m+5; System.out.println(m + " " + ch); int z = ++x * (y – –) – y ? Show the steps. 48. Write a Java expression for the following: ax5 + bx3+c 60. Name the kind of constructor called in the statement 49. What is the value of x1 if x=5? x1= ++x – x++ + --x below Caller a =new Caller(2,3); 50. Convert following do-while loop into for loop.