0% found this document useful (0 votes)
74 views

Java Activity 2

The document provides instructions for three Java programming activities: 1. Declare variables with given data types and initial values and output their names and values. 2. Get the sum of three numbers by declaring variables for the numbers and the sum. 3. Output the highest of three given numbers by declaring the variables and using conditional operators.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
74 views

Java Activity 2

The document provides instructions for three Java programming activities: 1. Declare variables with given data types and initial values and output their names and values. 2. Get the sum of three numbers by declaring variables for the numbers and the sum. 3. Output the highest of three given numbers by declaring the variables and using conditional operators.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

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

You might also like