Easy Code Required Please help

Hello I need some basic code that will do the following,
will read inputed integersand find the total and the average of inputed values and display them and program ends with input 0.
Thanks
Tim

Although the demo above is nice it will display the wrong average if the total is not evenly divisable by the integer count.For example if you go "java Demo 1 2 3 4 " you will get an average of 2 because 10 divided by 4 is 2.5 which cannot be represented by an integer value.
I propose the following program.It does not meet the requirements asked for 100 percent because it uses double values instead of integers and it ends by entering with no value. It does get rid of the command line arguments,is easier to use, and returns the right values.It is also very simple code.
import java.io.*;
import java.lang.Exception.*;
public class Average{
     public static void main(String args[]){
          String numberString = null;
          double number = 0;
          int count = 0;
          try{
               BufferedReader br = new BufferedReader(
                                    new InputStreamReader(System.in));
               while((numberString = br.readLine())!=null){
                    number += Double.parseDouble(numberString);
                    count++;
          catch(Exception e){}
          System.out.println("The total is "+ number+".");
          System.out.println("The average is "+ (number/count)+".");
}I hope this helps.

Similar Messages

  • I bought a iphone 5 from sprint in the contract i paid for it to work internationally, i paid out my contract so when i leave the u.s i can use it in trinidad. i am now in trinidad and when i put my sim in it says activation code required. please help

    how can i activate my phone to work with a carrier here?

    Did you restore the iPhone after Sprint told you that the unlock request had been processed? That's necessary to complete the unlock.
    http://support.apple.com/kb/HT5014
    If so, then you need to activate the iPhone with  your new carrier. Call them for the process.
    Regards.

  • Cannot restore my brand new iphone 4s ,got stuck in DFU mode and itunes shows error code (-1) please help?

    Cannot restore my brand new iphone 4s ,got stuck in DFU mode and itunes shows error code (-1) please help?
    repeatedly tried from diffierent computers and the same error code pops up (error -1)

    That's a hardware problem which will require a trip to the Apple store for evaluation, unless your phone has been jailbroken, then it's a corrupt hosts file (and we can't help you with that here as it is against the forum's terms of use).

  • What's wrong with my code? please help....

    when display button is clicked it must diplay the remarks but it didn't happen...
    what's wrong with my code? please help
    here is my code.....
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    public class Area extends Applet implements ItemListener,ActionListener
         {Label arlbl = new Label("AREA");
          Choice archc = new Choice();
          Label extlbl = new Label("EXPENDITURE TYPE");
          CheckboxGroup extchk = new CheckboxGroup();
              Checkbox fchk = new Checkbox("FOOD",extchk,true);
              Checkbox schk = new Checkbox("SHELTER",extchk,false);
              Checkbox echk = new Checkbox("EDUCATION",extchk,false);
              Checkbox uchk = new Checkbox("UTILITIES",extchk,false);
          Label exalbl = new Label("EXPENDITURE AMOUNT");
          TextField exatf = new TextField("",20);
          Label remlbl = new Label("REMARKS");
          TextField remtf = new TextField("",30);
          Button disbtn = new Button("DISPLAY");
          Button resbtn = new Button("RESET");
          String display;
          public void init()
              {add(arlbl);
               archc.add("MANILA");
               archc.add("MAKATI");
               archc.add("QUEZON");
               archc.add("PASAY");
               add(archc);
               archc.addItemListener(this);
               add(extlbl);
               add(fchk);
               fchk.addItemListener(this);
               add(schk);
               schk.addItemListener(this);     
               add(echk);
               echk.addItemListener(this);
               add(uchk);
               uchk.addItemListener(this);
               add(exalbl);
               add(exatf);
               add(remlbl);
               add(remtf);
               add(disbtn);
               disbtn.addActionListener(this);
               add(resbtn);
               resbtn.addActionListener(this);
         public void itemStateChanged(ItemEvent ex)
              {int n = archc.getSelectedIndex();
               if(n==0)
                   {if(fchk.getState())
                         {exatf.setText("10000.00");
                         display = archc.getSelectedItem();
                   if(schk.getState())
                        {exatf.setText("15000.00");
                        display = archc.getSelectedItem();
                   if(echk.getState())
                        {exatf.setText("24000.00");
                        display = archc.getSelectedItem();
                   if(uchk.getState())
                        {exatf.setText("8500.00");
                        display = archc.getSelectedItem();
              if(n==1)
                   {if(fchk.getState())
                        {exatf.setText("5000.00");
                        display = archc.getSelectedItem();
                   if(schk.getState())
                        {exatf.setText("11000.00");
                        display = archc.getSelectedItem();
                   if(echk.getState())
                        {exatf.setText("7500.00");
                        display = archc.getSelectedItem();
                   if(uchk.getState())
                        {exatf.setText("24000.00");
                        display = archc.getSelectedItem();
              if(n==2)
                   {if(fchk.getState())
                        {exatf.setText("13000.00");
                        display = archc.getSelectedItem();
                   if(schk.getState())
                        {exatf.setText("7000.00");
                        display = archc.getSelectedItem();
                   if(echk.getState())
                        {exatf.setText("27000.00");
                        display = archc.getSelectedItem();
                   if(uchk.getState())
                        {exatf.setText("6000.00");
                        display = archc.getSelectedItem();
              if(n==3)
                   {if(fchk.getState())
                        {exatf.setText("6000.00");
                        display = archc.getSelectedItem();
                   if(schk.getState())
                        {exatf.setText("9000.00");
                        display = archc.getSelectedItem();
                   if(echk.getState())
                        {exatf.setText("15000.00");
                        display = archc.getSelectedItem();
                   if(uchk.getState())
                        {exatf.setText("19000.00");
                        display = archc.getSelectedItem();
         public void actionPerformed(ActionEvent e)
              {if(e.getSource() == disbtn)
                    {String amtstr = exatf.getText();
                     int amt = Integer.parseInt(amtstr);
                        {if(amt > 8000)
                             {remtf.setText(display + " IS ABOVE BUDGET");
                        else
                             {remtf.setText(display + " IS BELOW BUDGET");
              if(e.getSource() == resbtn)
                   {archc.select(0);
                   fchk.setState(true);
                   schk.setState(false);
                   echk.setState(false);
                   uchk.setState(false);
                   exatf.setText("");
                   remtf.setText("");
    Edited by: lovely23 on Feb 28, 2009 11:24 PM

    Edit: thanks for cross-posting this question on another forum. I now see that I wasted my time trying to study your code in the java-forums to help you with an answer that had already been answered elsewhere (here). Do you realize that we are volunteers, that our time is as valuable as yours? Apparently not. Cross-post again and many here will not help you again. I know that I won't.

  • Photoshop CS6 could not update successfully.  Error codes Adobe Photoshop 13.0.1.3 Installation failed. Error Code: U44M1P7  Extension Manager 6.0.8 Update Installation failed. Error Code: U44M1P7  Please help me figure out how to call customer service. 

    Photoshop CS6 could not update successfully.  Error codes Adobe Photoshop 13.0.1.3 Installation failed. Error Code: U44M1P7  Extension Manager 6.0.8 Update Installation failed. Error Code: U44M1P7  Please help me figure out how to call customer service.  I would prefer to talk to someone directly.

    Are you using any disk cleaner or optimization tools like CleanMymac or Mackeeper?
    Regards,
    Ashutosh

  • I cannot restore my Iphone 4, I keep getting the error code 1611, please help and the Iphone keeps displaying the "Plug-In Itunes Symbol!??

    I cannot restore my Iphone 4, I keep getting the error code 1611, please help and the Iphone keeps displaying the "Plug-In Itunes Symbol!??

    http://tinyurl.com/nyj36v

  • Why when I change my debit card banking details and the postal code of where I stay is rejected,yet I know it is the correct postal code?please HELP me.

    Why is it that when I'm changing my debit card details and my postal address I receive a message that says my postal code is not valid?and yet I'm certain of what my postal code is.Please help.Regards,

    Ztshosane wrote:
    ... I receive a message that says my postal code is not valid?...
    Try here  >  http://support.apple.com/kb/TS1646
    If necessary... Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • HT1338 I receive this message ,repeatedly,when I try to update an App through App store:Error code 1009.Please help,what should I do?

    I receive this message ,repeatedly,when I try to update an App through App store:Error code 1009.Please help,what should I do?

    The App Store is not available in Iran.

  • Trying to download ios 3 getting error code 8288  please help

    Have a first generation ipod touch, trying to download ios 3 to computer getting error code 8288, please help.

    I finally solved this on my own. I installed iTunes 9.2 on my Mac. You can get it from here:
    http://support.apple.com/kb/dl1056
    Then I went to the iOS 3 purchase page here:
    http://support.apple.com/kb/HT2052
    and clicked the Purchasing link. It opens up iTunes. I connected my iPod touch G1 and did a check for system update. Miraculously, it found it this time and downloaded the update.
    No guarantee that this'll work for you, but I'm finally able to use my iPod touch again and put on some useful apps.

  • Hi.my itunes appear this error ERROE CODE:1009 please help me

    hi.my itunes appear this error ERROE CODE:1009 please help me

    Read my post. I don't know if you're having the same problem but I hope this helps. http://discussions.apple.com/thread.jspa?threadID=1351705&tstart=0
    Message was edited by: Happyfish

  • HT4759 When I try to return to my last backup, it tells me the IOS7 required, please help.

    When I try to return to my last backup, it tells me the IOS7 required, please help.

    Did you install the beta version of iOS 7 on your phone? If so, and you are a developer, you must post in the developer forums. If you are not a developer, you are stuck and will not be able to get assistance on these forums.

  • I ordered mac OS and I got the email for License and I didnt get the attachement for content code. Please help me getting the content code.

    I ordered mac OS and I got the email for License and I didnt get the attachement for content code. Please help me getting the content code.

    It's a two email process, one email has a locked pdf with the redemption code. The second email has the password to unlock the pdf. They come separetly, so you may have to wait for the 2nd to arrive.

  • Problem in Crystal Report 11 Logon failed Vendor Code 4060- Please help

    We are using VB 6.0 as front end, SQL 2005 Express edition as a data base server back end and crystal report 11 as reporting tool on Windows XP with SP2. The problem is, In the local system where DB exits the report generates fine. But if DB in network system the report will not work and it will ask for connection information (Provide necessary information to Logon to the chosen data source). We are using ODBC to connect the report. And if we give the correct password the report will generate
    I have checked all your help file and sample code but solution not found. please help as soon as possible
    Regards
    Karthik

    Hi Karthik,
    Ensure the report is using the correct connection information. For example, the data source name, server name, database name, and user name are correct.
    In a database-client test tool, ensure that the fields, tables, and procedures used by the report exist and that SQL queries can be executed against them.
    In the Crystal Reports designer, verify that the SQL query, as shown under the Database menu Show SQL Query option, does not contain syntax errors.
    If the SQL query shown in Crystal Reports is valid, execute the same SQL query through a database-client test tool.
    Is report working fine in designer?
    Which database connection are you using?
    Regards,
    Shweta

  • Blue screen error code. Please help.

    late 2008 version.
    Recently my school reinstalled windows 7 but after he did that, there was some blue screen error code which only appears while running on windows and everything is fine on the mac side.
    He reinstalled windows 7 again but the blue screen error code started again. He said that it could be that my apple disc is not original which caused the error code, however last year they were able to installed windows 7 without any issue. He also said that it could be the hard drive problem.
    Another problem I have is that while on windows the hard disk drives doesn't show the mac too.
    Please help! Much appreciated if any of you can help me out.

    Unless you run a VM such as Parallels, you're not going to be able to see your Mac disk using Boot Camp. If I were you, I'd see about getting Parallels Desktop and installing Windows 7 on it. You can then inter-operate with both systems.
    Clinton

  • HT1339 ipod not recognized by my computer, it says "Windows has stopped this device because it has reported problems. (Code 43)" please help

    please help...
    my computer is not recognizing my ipod classic gen 5. it shows the sad face then i did the basic troubleshooting until logo comes out...
    still my computer is not recognizing my ipod.. it still says "Windows has stopped this device because it has reported problems. (Code 43)"

    See here: iPod displays a sad iPod icon
    Note that it's often a good sign of a hardware issue with the iPod's hard drive meaning the iPod will need to be serviced or replaced.
    B-rock

Maybe you are looking for

  • Lightroom can't find external disk by itself

    Since uprgrading to Lightroom 2 (currently 2.2) I'm having this strange problem (this is on a Macbook Pro (OSX 10.5.6). I keep my photo's and my catalog on an external SATAlink harddrive. Often when I start Lightroom, it tells me that it can't find m

  • Why is my iPad 2 no longer able to screen share to external monitor?

    I used to connect my ipad 2 to various shared displays via HDMI and VGA converter cords quite frequently. The other day I connected and no signal is found...tried multiple screens, projector and different cords. Convinced its my iPad. Fixable? Hardwa

  • Please Guys this is the OO Forum not General Abap QUESTIONS.

    Hi everyone This is the OO Forum. There's often stuff here which really has nothing to do with OO. <b>For example the question on Table Controls and BDC -- sorry poster of that topic I'm not trying to have a go at you but defintely the wrong forum fo

  • AFAB ABAP runtime error  SAPSQL_ARRAY_INSERT_DUPREC

    Hi, Please, can somebody help me? When running AFAB for period 08 2009, the job gets cancelled and the job log says: The ABAP/4 Open SQL array insert results in duplicate database records. If you use an ABAP/4 Open SQL array insert to insert a record

  • Multiple NOT-IN selection from within Forms 6i

    I have a form, in which the user can put several varchar2 IDs (es. 'A0', 'B3', 'CJ',...). Then, I have to execute a query like this: INSERT INTO FOO SELECT * FROM BAR WHERE ID NOT IN (...values put by the user...) - The list of the user values has an