I am currently taking my first programming class in college and so far have been very good with understanding how to code basic things. This latest assignment has me confused and stumped.
My assignment is to:
- Accept numeric input from the user (integer value)
- Print out the square and cube of the number entered.
- Make sure that the number is > 0.
- Repeat the above three times.
- If the number entered is <= 0 then end the program, telling the user why.
My issue is that I am unsure how the variables are to be set for this and how exactly to add the loop to repeat the process 3 times.
This is all I have so far and do not know where to go from here, any help would be appreciated. Thank you
import java.io.*;
public class Assignment3 //class name here, same as file name
{
public Assignment3() throws IOException{ //constructor, place class name here
// use BufferedReader class to input from the keyboard
// declare a variable of type BufferedReader
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
//declare variable for input
String inputString;
// houseKeeping()
String yourNumber;
int number;
int totalSquare = 0;
int totalCube = 0;
int count;
int badNumber=0;
String squareCube = " Your number squared is" +square +"your number cubed is"+cube;
System.out.print("Enter a number: ");
inputString = input.readLine();
yourNumber = inputString;
}//end constructor
}
public static void main(String [] args) throws IOException
{
new Assignment3(); //class constructor name
}