Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello, I'm trying to write a program in JAVA, to calculate the number of integer values entered as a string by the user and work out the average of numbers. The final output should display the numbers entered and show the average.
e.g. The average of 22 34 58 98 23 is 43.4
==========================================
here is the code i came up with.import java.io.*;
class ValidationExample{
public static void main (String args[]) {
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String testString="";
int testNumber;
boolean inputOK=true;
do{
try{
System.out.println("Enter a number under 10000: ");
testString=in.readLine();
testNumber=Integer.parseInt(testString);
System.out.println("Second bit");
inputOK=true;
if (testNumber>10000){
inputOK=false;
}
}
catch (IOException e1){
System.out.println("Exception occurred!");
inputOK=false;
}
catch (NumberFormatException e2){
System.out.println("Error occurred: "+e2);
inputOK=false;
}
}while (inputOK==false);System.out.println("Number entered is valid");
System.out.println(testString);
}
}

![]() |
sizeof the queryin odbc
|
net send+VB
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |