Labs

These labs require conditional logic. Refer to this section's content for examples. There are many labs in this section. If you do not finish all of them, you can do so later.

  1. Write a program that accepts a number as input and prints a message stating whether the number is positive or negative.

(Solution: NumSign.java)

  1. Modify your solution to (1) so that if zero is entered, it prints a message saying so.

(Solution: NumSignZero.java)

  1. Write a program that prompts the user to enter a number and prints a message stating whether the number is odd or even. Modify your program to add a message stating whether the number is divisible by 10. Add another message stating whether the number is divisible by 100.

(Solution: NumFactors.java)

  1. Write a program that asks for a temperature and scale.

  2. If the scale is C, c, Celsius, or celsius, convert the number from Celsius to Fahrenheit with the formula Fahrenheit = (9.0/5.0 Celsius) + 32.

  3. If the scale is F, f, Fahrenheit, or fahrenheit, convert the number from Fahrenheit to Celsius with the formula Celsius = 5.0/9.0 (Fahrenheit - 32).
  4. Depending on the scale, the output should look like 32 degrees Fahrenheit is 0 degrees Celsius.
  5. If the scale is invalid, print an error message.

(Solution: IfCelsFahr.java)


Prev -- Up