LE1 - Java lecture lol PDF

Title LE1 - Java lecture lol
Course Introductory mathematical analysis
Institution Jubail University College
Pages 3
File Size 95.2 KB
File Type PDF
Total Downloads 46
Total Views 145

Summary

Java lecture lol...


Description

Lab Exercise 1

1. Practice on Self-Test Exercises of the chapter. 2. Convert the following statements and expressions into their corresponding java code. Number 1= 3(4) + 12.5 Number 2= 4/ 2 Number 3= Number 1 - Number 2 +1 Number 3=Number 3 +1 Number 3=Number 3 -1 Print out the variables Number1, Number2, and Number3

3. Write a Java program to print 'Hello' on screen and then print your name on a separate line. 4. Write a Java program to display the result of the following operations. -5 + 8 x 6 (55+9) % 9 (20 + -3) (5 ÷ 8 ) ( 5 + 15 ÷ 3) ( 2 - 8 % 3 )

5. Write a Java program to display the result of the following. 125 + 24 125 - 24 125 x 24 125 ÷ 24 125 mod 24 NOT ( -50 ) 6. Write a Java program to compute the given expression and display the output. ((25.5 x 3.5 - 3.5 x 3.5) ÷ (40.5 - 4.5)) 7. Write a Java program to compute and display the result of the given formula. 4.0 x (1 - (1.0÷3) + (1.0÷5) - (1.0÷7) + (1.0÷9) - (1.0÷11))

8. Trace the following piece of code and find out the value of num1, num2, and num3 in

each line. What is the output of this code?

class PreIncrement { public static void main(String args[]) { int num1; int num2; int num3;

num1 = 100; num2 = ++num1; num3 = num2++ + ++num1;

System.out.println("num1 = " + num1); System.out.println("num2 = " + num2); System.out.println("num3 = " + num3); }

}

9. Trace the following piece of code and find out the value of i in each line. What is the

output of this code? class PrePostDemo { public static void main(String[] args){ int i = 3; i++;

System.out.println(i); ++i;

System.out.println(i);

System.out.println(++i);

System.out.println(i++);

System.out.println(i); } }

10. Write one line of code for each of the following. a. Declare a variable of type integer and initialize it with the value 5. b. Declare a variable of type Boolean and initialize it with the value true. c. Declare a variable of type character and initialize it with the value A. d. Declare a variable of type double and initialize it with the value 13.2254 e. Declare an object of type string and initialize it with the string “hello world!” f. Define an empty string. g. Define a constant integer variable and assign it the value 20. h. Display and print all the variables’ values you defined in one line...


Similar Free PDFs