Lab Exercise 2 - PredefinedClass
Lab Exercise 2 - PredefinedClass
1. Write TWO (2) different ways to create an object from the String class.
Answer :
1- String name = new String(“Micheal”);
2- String name = “Micheal”;
Answer :
-,blu
3. Give your description on the output that will be produced by the execution of the following
statements.
Random rd = new Random();
System.out.println(rd.nextInt(41) + 10);
Answer :
The output will be the sum of random number from a range of 10 to 50.
4. Write Java code segment that use class Random to generate two random numbers that is
greater than or equal to 0, and less than 100 and store the values into local variable num1 and
num2. Then use class Math to determine and display the largest between both values.
Answer :
Output :
Answer :
abcabc
Answer :
The value is 3.0 or 2.0
6. Class Scanner in Java is used to read input from the console. Answer all of the following
questions:
Answer :
b) By using the object input, read two integer values and assigned to variable x and y.
Answer :
Int x = input.nextInt()
Int y = input.nextInt()
Answer :
Math.multiplyExact(x, y));
7. Given below are the statements that declare and create two String objects
a. Write a Java statement to display the total length of the text1, text2 and text3.
Answer :
Output :