SignUp for membership.

Forums

Pantheon Gaming :: Forums :: General :: Tutorials
Buri Needs Help With Java Home work << Previous thread | Next thread >>
Moderators: horus, PAN Ku, PAN Horus, Pan Morpheus, Pan Serapis, PAN Kane, PAN Bishamon, PAN Crom, Pan Cizin, PAN HA!
This thread is now closed
Author Post
PAN Buri
Tue Mar 23 2010, 05:59PM
the five-o

Registered Member #245

Posts: 530
okay here is the prompt and i have no idea how to do this

Design and implement a program that reads a series of 10 integers from the user and prints their average. Read each input values as a string , and then attempt to convert it to an integer using the Integer.parseInt method. if this process throws a NumberFormatExceptio n (meaning that the input is not a valid number), print an appropriate error message and prompt for the number again. Continue reading values until 10 valid integers have been entered.



help a buri out buri will be most appreciative



Buri:
-Primeval being of Germanic myth. Formed from a salty block of ice,Buri was the father of Bor, who in turn fathered the gods Odin,Vili and Ve.
Back to top
Website
PAN Kanassa
Tue Mar 23 2010, 09:28PM
He Who Speaks Low

Registered Member #440

Posts: 2492
I know this isn't completely what you need, I think it's a start...been like 3 years since I've touched Java and tried learning other languages in between...


Scanner scanner = ne w Scanner(System.in) ;

String[]  numberString = new  String[9]; //0-9 = 10 numberz
Int[]  numberInt = new Int [9]; // the array to convert  the strings into?

for (int i=0;  i >= 9; i++) // will ask you for a n umber 10 times
{
try
{
    System.out.print ln("GIMME NUMBER "  + String[i+1] + ":  "); // ask for whatever num ber you're on
    scanner[i]  = scanner.nextLine( ); //accept input
}
catch (NumberFormatE xception n)
{
    System.out.print ln(" MUST ENTER A VALID N UMBER!!!!!!");
}    
}




"To kill them teaches them nothing. You cannot exterminate them because from their seed comes more with greater hatred. Prison is nothing. Prison only makes hatred. That all our enemies should learn."
Back to top
PAN Kanassa
Tue Mar 23 2010, 09:31PM
He Who Speaks Low

Registered Member #440

Posts: 2492
I left out the header stuff and the main class and what not, and I went brain dead as far as accepting the string and converting to an int. I know its like:

variable = Integer.parseInt(" string");

Good luck!



"To kill them teaches them nothing. You cannot exterminate them because from their seed comes more with greater hatred. Prison is nothing. Prison only makes hatred. That all our enemies should learn."
Back to top
 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System