Hi!
Would you like to get the 1. input, 2. do the calculation, 3. print
something out, and then begin with 1.?
For this i modified your code a bit:
package javaapplication1;
import java.io.*;
/**
*
* @author Administrator
*/
public class Main{
int number, sum, temp;
BufferedReader in;
String s1;
/** Creates a new instance of Main */
public Main() {
int number = 0, sum = 0, temp = 0;
in = new BufferedReader( new InputStreamReader(System.in) );
s1 = null;
}
/**
* @param args the command line arguments
*/
public void commandLine(){
//BufferedReader in = new BufferedReader( //define it as a
global variable, so we don't need
//new InputStreamReader(System.in)); //to initialize it
each time, commandLine() is called.
//String s1 = null;
int integer = 0;
try
{
System.out.print("Enter any positive integer : ");
s1 = in.readLine();
integer = Integer.parseInt(s1);
}
catch(IOException ioex)
{
System.out.println("Input error");
System.exit(1);
}
catch(NumberFormatException nfex)
{
System.out.println("\"" + nfex.getMessage() +
"\" is not numeric");
System.exit(9);
}
System.out.println("Thanks for the number, " + s1);
Sum(integer, temp, sum);
}
public void Sum(int number, int temp, int sum){
do{
temp = number % 10;
sum = sum + temp;
number = number / 10;
}
while(number > 0);
System.out.print("Those digits added = " + sum);
//System.exit(1); //if you call this, the program will quit
after the first Sum()
}
public static void main(String[] args) {
Main test;
test = new Main();
while(true) { //calling commandLine() in an endless loop. With
CTRL+C you can terminate the program!
test.commandLine();
}
}
}
kauloha@comcast.net schrieb:
> Thanks for the quick response, yeah a start of a semester for me, I
> wrote this in netbeans, apparently I'm not sure how to make it run via
> command line.
kauloha@comcast.net - 17 Feb 2005 14:27 GMT
Thanks a lot, I'll try that out,