[go: up one dir, main page]

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

Java Worksheet 2

This document is a worksheet for Class XII Information Technology focusing on Java programming. It includes exercises to predict outputs of given code snippets, write code for string manipulation, and array initialization. Additionally, it contains tasks to complete code segments related to arrays and string operations.

Uploaded by

Saradha S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views2 pages

Java Worksheet 2

This document is a worksheet for Class XII Information Technology focusing on Java programming. It includes exercises to predict outputs of given code snippets, write code for string manipulation, and array initialization. Additionally, it contains tasks to complete code segments related to arrays and string operations.

Uploaded by

Saradha S
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CLASS: XII INFORMATION TECHNOLOGY (802)

DATE:10.07.2024 WORKSHEET 2 (JAVA PROGRAMMING )


I. Predict the output of the following code:
1. public class Example {
public static void main(String[] args) {
String str1 = "hello";
String str2 = "HELLO";
boolean isEqual = str1.equalsIgnoreCase(str2);
System.out.println("Strings are equal: " + isEqual);
}
}

2. public class IndexOfExample {


public static void main(String[] args) {
String str = "Hello, World!";
int index = str.indexOf('o');
System.out.println("Index of 'o': " + index);
}
}
II. 1.Write the code to concatenate two strings:
2.Write the code to replace all occurrences of a character in a string:
3.Complete the following code to convert a string to uppercase:
public class UpperCase {
public static void main(String[] args) {
String str = "hello";
String upperStr = str.__________();
System.out.println("Uppercase String: " + upperStr);
}
}

III. Complete the following code to declare and initialize an array of characters with
values 'a', 'b', 'c' and print its length:
1. public class ArrayExample4 {
public static void main(String[] args) {
// Fill in the blanks
______ [] letters = { ___, ___, ___ };

System.out.println("The length of the array is: " + letters.______);


}
}

2. Write the code to declare and initialize an array of doubles with values 1.1, 2.2, 3.3
and modify the second element:(array name : Numbers)
3. Write the code to declare an array of strings with 3 elements and assign values to
them.(Array name :Fruits)
IV. Predict the output of the following code:
1. public class PredictOutput3 {
public static void main(String[] args) {
char[] letters = {'a', 'b', 'c', 'd', 'e'};
for (int i = 0; i < letters.length; i += 2) {
System.out.print(letters[i] + " ");
}
}
}
2. public class PredictOutput2 {
public static void main(String[] args) {
String[] fruits = {"Apple", "Banana", "Cherry"};
for (int i = fruits.length - 1; i >= 0; i--) {
System.out.print(fruits[i] + " ");
}
}
}

You might also like