Uploaded by ianconan.juanico

JavaActivity2

advertisement
1. Create a Java Class named “IT233_JavaActivity2_1”.
Given the table below, declare the following variables
with the corresponding data types and initialization values.
Output to the screen the variable names together with the values.
Variable Name
Data Type
Initial Value
number
integer
10
letter
character
a
result
boolean
true
str
String
hello
The following should be the expected screen output,
number = 10
letter = a
result = true
str = hello
2. Create a Java Class named IT233_JavaActivity2_2. Create a program
That gets the sum of three numbers. Let the values of the three numbers
Be: 10, 20, 45. The expected output is,
Variable Name
Data Type
Initial Value
num1
integer
10
num2
integer
20
num3
integer
45
sum
integer
number 1 = 10
number 2 = 20
number 3 = 45
sum is = 75
3. Create a Java class named IT233_JavaActivity2_3. Given three numbers,
Write a program that outputs the number with the greatest value among the
three. Use the conditional operator ?: that we have studied so far
(HINT: You will need to use two sets of ?: to solve this problem).
Given the numbers 10, 23 and 5, your program should output,
Number 1= 10
Number 2 = 23
Number 3 = 5
The highest number is = 23
Download