ICSE 2018/Computer Applications/ Homework-5 Date of Submission: 23-03-2017
(a) What is the difference between the statements given below:
i) int x=5; ii) final int x=5; (b) Using a suitable example differentiate between() an object and a class. (c) Write a Java expression for: D=
(d) Name the java keyword that:
(i) is used to finish the execution of a method (ii) is used to differentiate between class method and an object method. (e) What will be the result stored in n after the following expression is evaluated? (i) int n= “Rajesh.indexOf(“b”); (ii) int n= “Mohan Meena”.indexOf(“n”); (iii) int n= “Mohan Meena”.lastIndexOf(“n”); (iv) int n= “Mohan Meena”.indexOf(“r”); (f) Rewrite the following using ternary operator: if(x%2= =0) System.out.println(“Divisible by 2”); else System.out.println(“Not divisible by 2”); (g) Give the output of the given for loop. Also write the equivalent while loop for the given for loop. for(int x = 100; x>=10 ; x-=10) { System.out.println(x+ “\n”); } (h) Analyze the given program segment and answer the following questions: (i) Write the output of the following segment. (ii) How many times the loop body will be executed? int m=0; while(m<=20) { m=m+5; if (m%3= =0) break; else if(m%5= =0) System.out.println(m); continue; } (i) Write a Program in Java to input a number and check whether it is a DISARIUM NUMBER or not. Note: A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example 135 is a DISARIUM (Workings 11+32+53 = 135, some other DISARIUM are 89, 175, 518 etc)