0% found this document useful (0 votes)
6 views2 pages

Worksheet 2

The document contains a series of questions and instructions related to Java programming concepts, including control flow statements, arrays, string manipulation, user input, and access modifiers. It includes one-mark, two-mark, and four-mark questions that require definitions, code examples, and explanations of various Java features. The document emphasizes the importance of providing examples and starting code with 'Package'.

Uploaded by

satinder kaur
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
6 views2 pages

Worksheet 2

The document contains a series of questions and instructions related to Java programming concepts, including control flow statements, arrays, string manipulation, user input, and access modifiers. It includes one-mark, two-mark, and four-mark questions that require definitions, code examples, and explanations of various Java features. The document emphasizes the importance of providing examples and starting code with 'Package'.

Uploaded by

satinder kaur
Copyright
© © All Rights Reserved
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

Topics:- Control Flow statements, Array, Array Manipulation, String Manipulation, Java

User Input, Access Modifier

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’.

One Mark Questions

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

12. Differentiate between while and do while loop.


13. How Switch statement works in a JAVA Program?
14. Write steps of a program to print the squares of numbers from 1 to 5 using “for” loop.
15. What are JAVA Keywords?
16. What are Java Identifier?
17. What are various types of Access modifier?
18. What is the use of nextInt() and nextLine() method?
19. What will be the output after the execution of the following code snippet? Give reason.
int b=20;
switch(b)
{
default: System.out.println(“LION”);
}
20. What will be the output after the execution of the following code snippet? Give reason.
public class Main
{
public static void main(String[] args) {
if(1>3)
System.out.println("Know Program");
}
}
21. Rewrite the code with the help of ‘for’ loop and predict the output.

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.

You might also like