Exercise A3
Java Fundamentals exercises
Wk2 Ex A3
- Write a program called AssignmentTests. Declare and initialize an integer x to 0. Take in the x value from the user. Evaluate x, if x is between 1 and 5 inclusive output the square of x; if x is between 6 and 10 inclusive output the cube of x; if x is less than or equal to 0 or greater than 10 then flag an error.
Enter integer (1..10) : 0
Input value outside of range 1..10: 0
Input = 0
Enter integer (1..10) : 11
Input value outside of range 1..10: 11
Input 11
Enter integer (1..10) : 1
The square of 1 is 1.0
Input 1
Enter integer (1..10) : 5
The square of 5 is 25.0
Input 5
Enter integer (1..10) : 6
The cube of 6 is 216.0
Input 6
Enter integer (1..10) : 10
The cube of 10 is 1000.0
Input 10