# ASSIGNMENT.JAVA

Write a program called Assignment4 (saved in a file Assignment4.java) that reads in a sequence of

positive integers until a user enters -1 to quit (we don't know how many numbers the user may enter)

The loop continues to ask for user input until the user enters negative one:

Enter a positive integer. Enter -1 to quit.

For each positive integer, check if it is a prime number or not.

If it is prime then print out:

The number X is a prime number.

If it is not prime print out:

The number X is not a prime number.

Note that X is a positive number entered by the user

Once the user enters -1, then the program stops asking for more positive integers, and computes the

maximum and minimum among integers entered by the user, and the sum, the count, and the average

of these integers. These computations DO NOT include -1 -- the last read number.

(note that max, min, sum, and count will be computed through iterations of a loop, see the example

Average.java in your book)

Your average should be formatted with two digits to the right of the decimal point.

Part 2: for each positive integer, we need to determine if it is a prime number or not.

A prime number (integer) is an integer that can be divided only by itself and 1. For example, 7 is

a prime number and 6 is not (6 can be divided by 2 and 3). We can check if an integer can be

divided by another integer using the remainder operator (%). If the remainder is 0, it can be

divided. And we need to check this for all integers between 2 and n-1 for a positive integer n.

Hint: Write a separate program to find if a number is prime or not, and then include it to the first

part mentioned above.

positive integers until a user enters -1 to quit (we don't know how many numbers the user may enter)

The loop continues to ask for user input until the user enters negative one:

Enter a positive integer. Enter -1 to quit.

For each positive integer, check if it is a prime number or not.

If it is prime then print out:

The number X is a prime number.

If it is not prime print out:

The number X is not a prime number.

Note that X is a positive number entered by the user

Once the user enters -1, then the program stops asking for more positive integers, and computes the

maximum and minimum among integers entered by the user, and the sum, the count, and the average

of these integers. These computations DO NOT include -1 -- the last read number.

(note that max, min, sum, and count will be computed through iterations of a loop, see the example

Average.java in your book)

Your average should be formatted with two digits to the right of the decimal point.

Part 2: for each positive integer, we need to determine if it is a prime number or not.

A prime number (integer) is an integer that can be divided only by itself and 1. For example, 7 is

a prime number and 6 is not (6 can be divided by 2 and 3). We can check if an integer can be

divided by another integer using the remainder operator (%). If the remainder is 0, it can be

divided. And we need to check this for all integers between 2 and n-1 for a positive integer n.

Hint: Write a separate program to find if a number is prime or not, and then include it to the first

part mentioned above.

You'll get 1 file (3.4KB)