Computing.Net > Forums > Programming > Help with problem in JAVA...

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Help with problem in JAVA...

Reply to Message Icon

Name: eskiya
Date: January 11, 2003 at 08:50:10 Pacific
OS: Win2k & Linux
CPU/Ram: p2 300 256ram
Comment:

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);
}
}



Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


sizeof the queryin odbc net send+VB



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Help with problem in JAVA...

Help with problem in C www.computing.net/answers/programming/help-with-problem-in-c/5108.html

i Want some help with programming www.computing.net/answers/programming/i-want-some-help-with-programming/14929.html

Prime Number problem in java www.computing.net/answers/programming/prime-number-problem-in-java/12949.html