Hi,
I'm writing a program with a do while loop..ending on the condition that the user doesn't enter 'c' or 'C' but after the second iteration, the program just ends after asking the user to enter c or C to continue. here's what I have:
import java.io.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class CalculatingPI
{
public static void main ( String args[] ) throws IOException
{
int numberOfTerms, counter;
float denominator;
double calculation;
String inputValues;
char aLetter;
do {
counter =1;
calculation = 0;
denominator = 0;
inputValues = JOptionPane.showInputDialog(
"Please enter the number of terms to be calculated: " );
numberOfTerms = Integer.parseInt( inputValues );
System.out.println(numberOfTerms);
System.out.print ("Enter C to continue, any other key to end: "
;
aLetter = (char)System.in.read();
}while (( aLetter == 'c') || (aLetter == 'C'));
System.exit(0); //terminate the program
} [sig][/sig]
I'm writing a program with a do while loop..ending on the condition that the user doesn't enter 'c' or 'C' but after the second iteration, the program just ends after asking the user to enter c or C to continue. here's what I have:
import java.io.*;
import javax.swing.*;
import java.text.DecimalFormat;
public class CalculatingPI
{
public static void main ( String args[] ) throws IOException
{
int numberOfTerms, counter;
float denominator;
double calculation;
String inputValues;
char aLetter;
do {
counter =1;
calculation = 0;
denominator = 0;
inputValues = JOptionPane.showInputDialog(
"Please enter the number of terms to be calculated: " );
numberOfTerms = Integer.parseInt( inputValues );
System.out.println(numberOfTerms);
System.out.print ("Enter C to continue, any other key to end: "
aLetter = (char)System.in.read();
}while (( aLetter == 'c') || (aLetter == 'C'));
System.exit(0); //terminate the program
} [sig][/sig]