Worksheet 2
Worksheet 2
General Instructions
1. Underline the headings and keywords with pencil.
2. Give answers with the help of examples.
3. While writing the program code, start the answer with ‘Package’.
1. ……………. statement is used to execute a block of code matching one value out of many
possible values.
2. The ability of a computer to perform the same set of actions again and again is called ………..
3. ………………… determine whether a loop is entered or exited is constructed using relational
and logical operators.
4. A single pass through the loop is called an …………….
5. The …………….. statement after each case group terminates the switch and causes execution
to continue to the statements after the switch.
6. If there is no match for the expression with any case group, the statements in the ………………
part are executed in switch program.
7. If there is only one statement in the body of the loop, the set of curly braces enclosing the
body can be omitted. (TRUE/FALSE)
8. What is Infinite loop?
9. What are the three parts of ‘for’ loop?
10. What is length property?
11. What is the use ‘\t ‘ and ’\n’ in a program?
2 Marks Questions
int a=1;
while(a<4)
{
System.out.print(a + " ");
a++;
}
4 Marks Questions
22. What is Array and Array Index? How can we declare an Array?
23. Read the code carefully and give its output :
package javaprogarms;
public class StringDemo{
public static void main(String[]args)
{
String myString = "INFORMATION TECHNOLOGY";
System.out.println(myString.indexof(’E’));
System.out.println(myString.contains("NO"));
System.out.println(myString.length();
System.out.println(myString.replace(’O’,’*’));
System.out.println(myString.concat(’802’));
System.out.println(myString.charAt(6));
System.out.println(myString.endsWith(’ogy’));
}};
24. Write a JAVA Program to print sum of first 10 odd number.