Sheet 1 - Java Basics
Sheet 1 - Java Basics
1. Write program that asks the user for three one-digit numbers and then uses
them as units, tens, and hundreds to evaluate one 3-digit number out of them
Example:
Please enter units: 5
Please enter tens: 2
Please enter tens: 9
The number is: 925
2. Write a program that gets two positive integer numbers X and Y and
calculates X^Y. (Hint: using loops with multiplication, i.e., X^Y = X*X*X*…
Y times)
3. Write a program that reads the departure time of a train and the arrival time
and computers and displays the trip time. (Example: for Departure time 10:50
and Arrival time 12:10 the trip time will be 1 hr and 20 min).
4. Write a program to read a list of student's grades from the user and do the
following:
a. Check each element to see if it is a valid grade (the valid range is from 0
to 100). For each grade, the program displays either Valid or Invalid.
Count the number of invalid grades.
1
if they exist. The roots of the equations can be one of the following four
cases:
i. any x is a solution (if a = b = c = 0)
ii. no solution (if a = b = 0, c ~= 0)
iii. one real root (if a = 0, so the root is −c/b)
iv. two real or complex roots (if not any of the above cases)
Input Output
[0 0 0] Any x is a solution
[0 0 2] No solution
[0 1 3] -3
[1 -5 6] 2
6. Write a program to read two 1-D arrays from the user and compute how
many times each element in the first array occurs in the second array. Results
should be stored in an array.
Input [1 8 7 5] and [5 3 1 7 6 7 7] will produce output [1 0 3 1]