Question 1. Write a program to read in two strings and print out the difference (if there is any)

between two string, and which string should come first in lexicography order.

Example:

Enter string one: Small

Enter string two: Big

“Small” and “Big” are different by 17 units. “Big” should come

before “Small” in lexicography order.

Question 2. Write a program to prompt the user for an integer 0≤N≤1000 and list all the odd number from 1 to N. Use a while() loop to check for an appropriate input. List the numbers in multiple lines where each line contain only 10 odd numbers, each number is printed using printf() function with 4 units in width.

Example:

Enter the number N = -5

Error: 0 <= N <= 1000. Reenter.

Enter the number N = 1001

Error: 0 <= N <= 1000. Reenter.

Enter the number N = 30

1 3 5 7 9 11 13 15 17 19

21 23 25 27 29

Question 3. Write a program to prompt the user for an integer -100≤N≤100 and print out the sum of all even numbers from 0 to N inclusively (if N is positive) or from N to 0 (if N is negative). Use a while() loop to check for an appropriate input. Use printf() function to print out the result with 16 units in width and with a comma “,” to separate between thousands. If the sum is negative, print out the result within “()”.

Example:

Enter the number N = -106

Error: -100 <= N <= 100. Reenter.

Enter the number N = 101

Error: -100 <= N <= 100. Reenter.

Enter the number N = 10

Sum of even number from 0 to 10 is: 30

Enter the number N = 50

Sum of even number from 0 to 10 is: 650

Question 4. Write a program to prompt the user for a positive integer N≤10. Read exactly N numbers (can be fractional) from the users and return the number with maximum absolute value among N numbers you just read. Use a while() loop to check for an appropriate input.

Example:

Enter the number N = -10

Error: 0 < N <= 10. Reenter.

Enter the number N = 15

Error: 0 < N <= 10. Reenter.

Enter the number N = 5

Enter 5 numbers each separated by a space: 10.56 3.79 2.11 4.90 -

10000

The number with maximum absolute value is: -10000.

**Subject Computer Science Java Programming**