The Artima Developer Community
Sponsored Link

Java Answers Forum
average program

2 replies on 1 page. Most recent reply: Mar 29, 2002 12:50 AM by Aaron

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Aaron

Posts: 2
Nickname: goas
Registered: Mar, 2002

average program Posted: Mar 29, 2002 12:07 AM
Reply to this message Reply
Advertisement
This program is supposed to allow for the user to input any amount of numbers then when they typ stop it will average the numbers given and returned the number. But all it does as of now is not work.

import java.io.*;


public class DontStop{
static String STOP_WORD="stop";
static BufferedReader keyboard=new BufferedReader(new InputStreamReader(System.in));
public static void main(String arg[]) throws IOException {
System.out.println("This program calculates the average of numbers entered by the user");
System.out.println("After you have entered your last number, simply type STOP.");
doThis();
}
public static void doThis()throws IOException {
String choiceString = "a";
int choice = 0;
int count = 1;
double total=0;
double average=0;
while(!choiceString.equalsIgnoreCase(STOP_WORD)){
System.out.print(" Please enter number "+ count+": ");
}
if(choiceString.equalsIgnoreCase(STOP_WORD)){
count--;
System.out.println ("You entered "+count+" numbers with an average of "+total/count);
System.exit(0);
}//
}

public static double getNumber(String n)throws IOException{
double number=0;
try{
String numberString=keyboard.readLine();
number=Double.parseDouble(n);
}
catch(NumberF ormatException e){
System.out.println("Wanted a number, starting over");
doThis();
}
return number;
}//close getNumber
}//close DontStop


Singh M.

Posts: 154
Nickname: ms
Registered: Mar, 2002

Re: average program Posted: Mar 29, 2002 12:36 AM
Reply to this message Reply
your classmate John posted the same question.... You will be suspended for plagiarism if you get answer out of this forum.

Aaron

Posts: 2
Nickname: goas
Registered: Mar, 2002

Re: average program Posted: Mar 29, 2002 12:50 AM
Reply to this message Reply
Well I actualy put some work into mine, I though this was a help fourm. I just need some help debuging my code.

Flat View: This topic has 2 replies on 1 page
Topic: serial communication Previous Topic   Next Topic Topic: integers to strings

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use