Professional Documents
Culture Documents
Fall 23
Lab 2
SET: 1
Exercise #1: Write a Java program using for loop to print out “Hello World!” 25 times.
Exercise #2: Write a Java program using while loop to print out “Hello World!” 25 times.
Exercise #3: Write a Java program using for loop to find out the sum and the average of all
odd integers between 1 and 100.
Exercise#4: Write a java program that reads from the user up to 10 numbers, using while loop
with a SENTINEL, to count and add the positive values and then display the results. Your
program should terminate whenever it either reads 10 number or a any negative number.
SET 2:
Exirces#1: Salma learned recently about prime numbers. She can determine whether a number
is prime or not for small numbers, however, for large numbers she needs to make some
calculations. Salma asks you to write a java program to verify if a given number is "Prime" or
"not Prime". Remember that she may use your program for very large numbers.
1/2
Hint: the simplest way to determine if a number (N) is prime or not is to check if the numbers
from 2 to N-1 divide N without a remainder. (Moreover, stop at N/2 rather than N-1 is enough).
2/2