Java 12

REVIEW TOPIC 01 – PROGRAMMING BASICS

 

LESSON WORK

 

 

QUESTION 1


Create the famous Hello World program.  It is simply a program that will output “Hello World” to screen.  This is simply to make sure that you remember how to use Java and the IDE that you have chosen.

 

Save your work inside a file called Q1.java inside the folder called Topic01.  (Note that in Eclipse, we can create a folder by creating a project named Topic01.)

 

QUESTION 2


Create the famous Greeting program.  The program asks the user for his/her first name.  It then asks for the last name.  Finally, it outputs “Hello name” where the name is the full name of the user. 

 

Remember that the + symbol between two strings allows for string concatenation (combining).

 

Save your work inside a file called Q2.java inside the folder called Topic01.

 

QUESTION 3

 

Create a power program.  It simply asks the user for the value m and for the value n and outputs the value of mn.  Make use of the power function in the Math class.

 

Save your work inside a file called Q3.java inside the folder called Topic01.

 

QUESTION 4

 

Create the maximum program.  It simply asks the user to enter 2 numbers and outputs the largest one to screen.  Use the max function in the Math class.

 

Sample I/O:

 

         Please enter a number.

         4

         Please enter another number.

         2

         The largest number is 4.

 

You are to make your output match exactly the above sample output.  Notice the punctuation! 

 

Save your work inside a file called Q4.java inside the folder called Topic01.

 

QUESTION 5

 

Create a minimum/average program that gets 5 different numbers from the user and outputs both the minimum number and the average of the five numbers.

 

Unlike the program from the previous question, the program provides no instructions to the user.  The user simply needs to start typing numbers.

 

SAMPLE I/O:

5

10

7

4

9

min: 4
avg: 7.0

 

Save your work inside a file called Q5.java inside the folder called Topic01.

 

QUESTION 6

 

The % symbol, called mod, allows one to see the remainder between two numbers.

 

Use it to write the program that will get a number from the user and see the remainder of that number when it is divided by five.

 

Sample I/O #1:

 

         Please enter a number.

         23

         The remainder of 23 mod 5 is 3.

 

Sample I/O #2:

 

         Please enter a number.

         79

         The remainder of 79 mod 5 is 4.

 

Save your work inside a file called Q6.java inside the folder called Topic01.

 

QUESTION 7 (TIME PERMITTING)

 

Write a program that will use Math.random() to generate a random integer between 800 and 810 inclusively.

Save your work inside a file called Q7.java inside the folder called Topic01.