Please help as I don't know how to do this yet!
At the moment, my code will compile but it goes straight to the "Press any key to continue" prompt.
Check out my code and pay attention to the for loop.
import java.io.*;
public class CalculateBox
{
public static void main(String args []) throws IOException
{
String strHeight = "0", strWidth = "0";
float height = 0, width = 0, total = 0;
boolean heightDone = false, widthDone = false;
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
for(int j = 0; j > 0; System.exit(0))
{
String yesOrNo;
while(!heightDone)
{
try
{
System.out.println();
System.out.println("Enter the height of the box: ");
System.out.println();
strHeight = dataIn.readLine();
height = Float.parseFloat(strHeight);
if(height <= 0) throw new NumberFormatException ();
else heightDone = true;
}
catch(NumberFormatException e)
{
System.out.println();
System.out.println("Invalid height entry! - Try again");
}
} // end of while
while(!widthDone)
{
try
{
System.out.println();
System.out.println("Enter the width of the box: ");
System.out.println();
strWidth = dataIn.readLine();
width = Float.parseFloat(strWidth);
if(width <= 0) throw new NumberFormatException ();
else widthDone = true;
}
catch(NumberFormatException e)
{
System.out.println();
System.out.println("Invalid width entry! - Try again:");
}
} // end of while
total = height * width;
System.out.println();
System.out.println("The area = " + total);
System.out.println();
// this ain't a workin'
//=====================
System.out.print("Another calculation? y/n");
yesOrNo = dataIn.readLine();
if(yesOrNo == "n") j++;
//=====================
} // end of for loop
} // end of main
} // end of class CalculateBox

New Topic/Question
Reply



MultiQuote



|