Determining Largest and Smallest integers, without creating multiple ints

I created a program that reads a list of numbers (doubles) terminated by a sentinal value, and outputs the average. The do-while statement with the sentinal value termination uses only one specified integer, changed with the input of each new number. Now without specifying more integers is there a way i can determine the largest and smallest number on the list?
import java.util.*;
public class LabThree
    public static void main(String[] args)
        Scanner keyboard = new Scanner(System.in);
        int totaldoubles, max, min;
        double total, nextnum;
        String answer;
        do
         System.out.println();
         System.out.println("Enter a list of nonnegative integers");
            System.out.println("When you are finished with the list, enter a negative number");
            System.out.println();
            System.out.println("I will tell you the largest and smallest integer");
            System.out.println("and give you the average the list");
            totaldoubles = 0 ;
            total = 0;
            nextnum = keyboard.nextDouble();
            while (nextnum >= 0)
                total = total + nextnum;
                totaldoubles++;
                nextnum = keyboard.nextDouble();
            if (totaldoubles > 0)
                System.out.println("The average is: " + (total/totaldoubles));
            else
                System.out.println("No scores to average");
            System.out.println();
            System.out.println("Do you want to average another list?");
            System.out.println("Enter Yes or No");
            answer = keyboard.next();
        }while (answer.equalsIgnoreCase("yes"));
}Message was edited by:
thecynicle1
Message was edited by:
thecynicle1

ok i tried this:
import java.util.*;
public class LabThree
public static void main(String[] args)
Scanner keyboard = new Scanner(System.in);
int totaldoubles;
double total, nextnum, max, min;
String answer;
do
     System.out.println();
     System.out.println("Enter a list of nonnegative integers");
System.out.println("When you are finished with the list, enter a negative number");
System.out.println();
System.out.println("I will tell you the largest and smallest integer");
System.out.println("and give you the average the list");
totaldoubles = 0 ;
total = 0;
nextnum = keyboard.nextDouble();
max = nextnum;
min = nextnum;
while (nextnum >= 0)
total = total + nextnum;
totaldoubles++;
nextnum = keyboard.nextDouble();
if (nextnum > max)
max = nextnum;
else if (nextnum < min)
min = nextnum;
if (totaldoubles > 0)
System.out.println("The average is: " + (total/totaldoubles));
System.out.println("The largest number was: " + max);
else
System.out.println("No scores to average");
System.out.println();
System.out.println("Do you want to average another list?");
System.out.println("Enter Yes or No");
answer = keyboard.next();
}while (answer.equalsIgnoreCase("yes"));
But now the compiler is saying that the underlined "else" is without an if
Message was edited by:
thecynicle1
Message was edited by:
thecynicle1
Message was edited by:
thecynicle1

Similar Messages

  • Finding largest and smallest using inputStream

    I'm having trouble coming up with the logic to find the largest and smallest scores of an input stream. Am I on the write track, hints?
    import java.util.Scanner;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.PrintWriter;
    public class Exercise10
         public static void main(String[] args)
              //declare the filenames
              String fileIn = "in.txt";
              String fileOut = "out.txt";
              //use Scanner for input
              Scanner streamIn = null;
              //use PrintWriter for output
              PrintWriter streamOut = null;
              int count = 0;
              double sum = 0;
              double n;
              double large = 0;
              try
                   streamIn = new Scanner(new File(fileIn));
                   streamOut = new PrintWriter(fileOut);
              catch(FileNotFoundException e)
                   System.out.println("Error opening the file "+fileIn+" or "+fileOut+".\n");
                   System.exit(0);
              System.out.println("Scores have been outputted to " +fileOut+ ".\n");
              //loop if there is another line in fileIn
              while(streamIn.hasNextInt())
                   n = streamIn.nextInt();
                   double previous = n;
                   if(previous>n)
                        large = previous;
                   else
                        large = n;
                   //find the largest score in the file
                   if(n>= 0 && n<=100)
                        count++;
                        sum = sum + n;
                   else
                        streamOut.println("Your score is out of range.");
              //close the stream in
              streamIn.close();
              //write the information
              streamOut.println("There are " +count+" grades in the "+fileIn+ " file.");
              streamOut.println("The total sum of the grades is: "+sum);
              streamOut.println("The average is: "+sum / count);
              streamOut.println("The largest score is: "+large);
              //close the stream out, will not write unless closed.
              streamOut.close();
    }Edited by: brandonacoughlin on Nov 12, 2009 8:25 PM

    if(n>= 0 && n<=100)
                        //find the largest score in the file
                        if(n>=large)
                                  large = n;
                        //find the smallest score in the file
                        else if(n<=small)
                                  small = n;
                             }

  • Schedule Webi (and Crystal) report without creating a new instance

    Hi all,
    I'm looking for the way to not create a new instance of the report when we schedule a report? Is it any actions on the InfoObject object? Or is it just impossible to do?
    Thanks in advance !
    Edited by: jerome.vervier on Nov 21, 2011 11:40 AM

    Hi,
    With regards to your query, whenever a report is scheduled an instance of it will be created.
    Therefore, it is not possible to schedule a report without creating an instance.
    Regards,
    Shreyans

  • I use a PC for work and link it to Office 365. I also have an iphone and ipad. How do I synchronise these devices to Outlook without creating multiple copies of calendars?

    I use my PC for work (MS Office and Outlook). I also use Office 365. I also have an iPhone and iPad. I'm having difficulty getting Outlook to synchronise with Apple devices. I keep getting multiple copies of calendars and not being able to see contacts. Is there a process anywhere which describes the best way to manage these devices together? Or should I just give up on the PC and buy a MacBook or Air.

    Excellent. These guides got me as far as installing my preferred language pack, which gets added to the add-ons automatically (assuming the user says yes to the appearing question when Firefox is started).
    However, the GUI does not change unless the user enters "about:config" and changes the locale.
    Is there a way to do this from the command line? I mean, changing the locale settings.
    And preferrably for all users. So even when new users get added and they start Firefox the first time, they see it appearing with the preferred locale and not in English.

  • Splitting photos without creating multiple events.

    Is this possible? I have one event in iPhoto which covers three days. I would like all my photos from this event together but I want each day sectioned off in the same event, not split into multiple events. Highlighting the photos from each day and clicking "split" puts the days all in separate events where as I want them sectioned off, but together in ONE event. I hope I am making myself clear.
    My aim is to have it looking something like this:
    Event:
    Day 1
    Day 2
    Day 3
    NOT
    Event: Day 1
    Event: Day 2
    Event: Day 3

    tensocfan
    Now with Events as you cannot have Nested Events, but it's perfectly possible with Albums:
    File -> New Folder: Name it 3 Day Event
    Then three Albums (you can even make them smart Albums: Date is Whatever)
    And drag the Albums to the Folder.
    Regards
    TD

  • How to create multiple sip trunks between cucm and cisco unified sip proxy

    Dear Expert,
    Is there a way to create multiple sip trunks between CUCM and Cisco Unified SIP Proxy (CUSP)? How to achieve it without creating multiple IP interfaces on the CUSP module.
    CUCM: 8.5.1.10000-9
    CUSP: 8.5.2
    Thank you,
    .wan

    Hello Michael,
    This SIP trunk is part of UCCE solution, which used between CVP, CUSP, and CUCM.
    The requirements:
    1) To have different codecs for different type of calls, as the phones are at few countries
    2) To pass different number of digits from CUSP to CUCM for different call treatments
    .wan

  • How to monitor load on GWWS? and create Multiple GWWS ?

    Hi,
    I'm running Tuxedo 10gR3 and observed in OS level that GWWS process alone consume more than 10% of CPU all the time and some slowness are claimed by users.
    I need to check if this is normal (CPU %) by checking the load on GWWS and if needed to create multiple GWWS to distribute the load.
    OS: AIX5.3
    Number of CPU : 12
    Regards.

    Hi Todd;
    Thanks for the response, i have checked the stats for the GWWS but it's strange that i have all outbound stats at zero ? :
    >
    gws -i SPGWW01
    GWWS Instance : SPGWW01
    Inboud Statistics :
       Request Response Succ : 6051981
       Request Response Fail :  12405
                 Oneway Succ :      0
                 Oneway Fail :      0
                  Total Succ : 6051981
                  Total Fail :  12405
    Avg. Processing Time : 434.365 (ms)
    Outboud Statistics :
       Request Response Succ :      0
       Request Response Fail :      0
                 Oneway Succ :      0
                 Oneway Fail :      0
                  Total Succ :      0
                  Total Fail :      0
    Avg. Processing Time :  0.000 (ms)
       Total request Pending :     17
    Outbound request Pending :      0
        Active Thread Number :    113
    Regards.

  • Create multiple copies of a position- HCM Processes and Forms

    Hi Experts,
    Hope all are doing well.
    In my current project we using HCM PnF to create positions and copy positions. We are using the FPM interface.
    One of the requirements is to for copy position and the user can create multiple copies(max upto 30) of a position.
    How can this be achieved in HCM PnF?
    One answer will be advanced generic service. Do we have any other way of achieving this? If not, do we have any sample code where we use advance generic service to call SAP_PD/ or any code which might be helpful?
    Waiting for you answers.
    Thanks very much in advance.
    Regards,
    Saikat

    Hi Kalyan,
    Thanks for your reply.
    Yes, I understand that we will have to achieve that through advanced generic service.
    To be honest I haven't used advanced generic service for PD before and it will be helpful if you can give me some code(may be the one inside do operations and flush). With some sample code it will be easier for me.
    Many thanks.
    Saikat

  • How can I mass move symbols with their motion paths without creating new keyframes?

    I want to move a lot of symbols all at once if they are off centered or just need to be moved around to see differenr styles across the document, but I can't seem to move a lot of the symbols at once, only one at a time slexting their motion paths. It's rather annoying when I have items coming in at different times and have to re line everything up one by one if I want to move things even over by 1 px. Every time I slecect all my symbols and try to move them it just creates a new keyframe that they follow. Is there any tool or certian way to select the symbols and/or thier motion paths and move them without creating new key frames?

    Hi,
    There's no direct way of moving all the symbols/ motion tweens begining at different frames altogether, but the following steps should help you do it -
    1. Select a motion path on stage, goto Properties panel > Options menu (top left corner) and enable - Always show Motion Paths.
    2. Enable - Edit Multiple Frames option in the Timeline.
    3. Adjust the frame-markers in Timeline to show all your symbols, motion paths etc.
    4. Now that you see all your symbols and motion paths together, Select-all and Move them together. Or, use Shift + click to selectively select the Motion paths/objects and move them.
    Let me know if you have any doubts..
    Regards,
    Nipun

  • How to improve the speed of creating multiple strings from a char[]?

    Hi,
    I have a char[] and I want to create multiple Strings from the contents of this char[] at various offsets and of various lengths, without having to reallocate memory (my char[] is several tens of megabytes large). And the following function (from java/lang/String.java) would be perfect apart from the fact that it was designed so that only package-private classes may benefit from the speed improvements it offers:
        // Package private constructor which shares value array for speed.
        String(int offset, int count, char value[]) {
         this.value = value;
         this.offset = offset;
         this.count = count;
        }My first thought was to override the String class. But java.lang.String is final, so no good there. Plus it was a really bad idea to start with.
    My second thought was to make a java.lang.FastString which would then be package private, and could access the string's constructor, create a new string and then return it (thought I was real clever here) but no, apparently you cannot create a class within the package java.lang. Some sort of security issue.
    I am just wondering first if there is an easy way of forcing the compiler to obey me, or forcing it to allow me to access a package private constructer from outside the package. Either that, or some sort of security overrider, somehow.

    My laptop can create and garbage collect 10,000,000 Strings per second from char[] "hello world". That creates about 200 MB of strings per second (char = 2B). Test program below.
    A char[] "tens of megabytes large" shouldn't take too large a fraction of a second to convert to a bunch of Strings. Except, say, if the computer is memory-starved and swapping to disk. What kind of times do you get? Is it at all possible that there is something else slowing things down?
    using (literally) millions of charAt()'s would be
    suicide (code-wise) for me and my program."java -server" gives me 600,000,000 charAt()'s per second (actually more, but I put in some addition to prevent Hotspot from optimizing everything away). Test program below. A million calls would be 1.7 milliseconds. Using char[n] instead of charAt(n) is faster by a factor of less than 2. Are you sure millions of charAt()'s is a huge problem?
    public class t1
        public static void main(String args[])
         char hello[] = "hello world".toCharArray();
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 1000 * 1000; m++) {
              String s1 = new String(hello);
              String s2 = new String(hello);
              String s3 = new String(hello);
              String s4 = new String(hello);
              String s5 = new String(hello);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    public class t2
        static int global;
        public static void main(String args[])
         String hello = "hello world";
         for (int n = 0; n < 10; n++) {
             long start = System.currentTimeMillis();
             for (int m = 0; m < 10 * 1000 * 1000; m++) {
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
              global +=
                  hello.charAt(0) + hello.charAt(1) + hello.charAt(2) +
                  hello.charAt(3) + hello.charAt(4) + hello.charAt(5) +
                  hello.charAt(6) + hello.charAt(7) + hello.charAt(8) +
                  hello.charAt(9);
             long end = System.currentTimeMillis();
             System.out.println("time " + (end - start) + " ms");
    }

  • Configuring Legal Entity as Operating Unit without creating new OU

    Hi,
    I have read the doucment "120funmo.pdf" on page 25/60. Eastern operations can be created as Legal entity and identify as Operating Unit and Inventory organization without creating any new OU and INV. ORG.
    How this can be achieved?
    I have created Ledger and "Eastern Operations" as Legal Entity and trying to find a way to identify it as OU and INV. ORG.
    Thanks,
    Narendra
    Edited by: 869369 on Jun 29, 2011 11:51 PM

    Suppliers are across all Operating Units so you see the same set across Operating Units.
    Supplier Sites are partitioned by Operating Unit.
    Regards,
    Gareth

  • Use splitter to create multiple text file

    Hello I have one view as source and would like to create multiple target text files based on different condition. What I am doing is that I am using SPLITTER which contain one INGRP1 and three OUTGRP( nameley TR1, TR2 and TR3) and one default REMAINING_ROWS ( what is the purpose of the REMAINING_ROWS?). So I mapped view to INGRP1 of the splitter and then added the different SPLITT condition in the condition wizard, for example :
    for TR1
    COMMISSION_TYPE='P' and
    rownum <= 65000
    for TR2
    COMMISSION_TYPE='P' and
    rownum > 65000
    and for TR3
    COMMISSION_TYPE='A'
    After this since I have to create 3 comma delimted text files, I have used 3 expression for each individual splitt condition. In the expression what I am doing is that I am just concating all the fileds and then output of each expression goes to three different text files.
    When I am deploying the mapping, it is coming up several errors such as :
    1): PLS-00201: identifier 'COMMISSION_TYPE' must be declared
    (2): PL/SQL: Statement ignored
    (3): PLS-00201: identifier 'COMMISSION_TYPE' must be declared
    (4): PL/SQL: Statement ignored
    (5): PLS-00201: identifier 'COMMISSION_TYPE' must be declared
    (6): PL/SQL: Statement ignored
    (7): PLS-00201: identifier 'START_INDEX' must be declared
    (8): PL/SQL: Statement ignored
    (9): PLS-00201: identifier 'T_EXPR_ASSET_1_OUTPUT_ASSET$0' must be declared
    (10): PL/SQL: Item ignored
    (11): PLS-00201: identifier 'T_ROWKEY_SPLIT_2' must be declared
    (12): PL/SQL: Item ignored
    (13): PLS-00201: identifier 'T_CPPASSET_0_OUTPUT_ASSET$0' must be declared
    (14): PL/SQL: Item ignored
    (15): PLS-00801: internal error [21076]
    (16): PL/SQL: Item ignored
    (17): PLS-00801: internal error [21076]
    (18): PL/SQL: Item ignored
    (19): PLS-00801: internal error [21076]
    (20): PL/SQL: Item ignored
    Why I am getting these errors, why OWB generated code could not identify COMMISSION_TYPE filed?
    Please help me.
    Suhail

    I am really very very sorry, its my fault. I was not mapping COMMISSION_TYPE from view to splitter.

  • Create multiple sales order

    Dear all,
       how to create multiple sales order using rfc's.
                                                  regards,
                                                   malli.

    I Don't think there is a RFC for it. But you can create the Function and make it RFC enable.
    the Interface of The RFC should allow and take information to create multiple orders.
    inside the RFC ,
    you need to loop the table parameters
    since the main table contains information of all the orders.
    and
    Call the BAPI
    BAPI_SALESORDER_CREATEFROMDAT2
    and pass appropriate information for each loop and create order.

  • How to Delete IDoc by Sara Transaction without create a file

    Hi guru´s
    I have a problem.
    I am using SARA transaction for Archiving IDoc, but I need to execute and eliminate recods without create a file. In R3 version we have this option in RSEXARCA, but in ECC 6.0 not.
    How to execute it?
    Some one have the same problem?
    Do you have any documentation about Archiving in Ecc 60.0?
    Thanks in Advance.
    B. Regards
    Cristina

    Hi guru´s
    I have a problem.
    I am using SARA transaction for Archiving IDoc, but I need to execute and eliminate recods without create a file. In R3 version we have this option in RSEXARCA, but in ECC 6.0 not.
    How to execute it?
    Some one have the same problem?
    Do you have any documentation about Archiving in Ecc 60.0?
    Thanks in Advance.
    B. Regards
    Cristina

  • HT5114 How can I create multiple accounts without the necessity to create multiple email addresses?  I now have 2 i-phones (mine and my wife's#, 1 i-pad #mine#, 1 i-pad mini #10 year old's#, and 1 I-pod touch #11 year old's).  I would like to maintain pur

    How can I create multiple accounts without the necessity to create multiple email addresses?  I now have 2 i-phones (mine and my wife's), 1 i-pad (mine), 1 i-pad mini (10 year old's), and 1 I-pod touch (11 year old's).  I would like to maintain purchase control, but would like to be able to have a separate account ID for each person.  Is that possible?

    Each email address can only be on one iTunes account, and all purchases are tied to the account that buys them. If you want to have separate iTunes accounts on each then you will need separate email accounts for each iTunes account

Maybe you are looking for

  • ETL Load error

    Hi When i ran the ETL load for Project analytics , it errored out. In the DAC , these 3 items errored 1. SIL_GlobalCurrencyGeneral_Update 2. SDE_ORA_UserDimension 3. SDE_ORA_EmployeeDimension below is the error from the log file. Any help will be app

  • Eyedropper tool isn't working correctly in Levels, Curves adjustments

    I have installed PS CS 5 Extended on a new computer running Vista Home Premium.  No other version of Photoshop has ever been installed on this system. The problem that I am encountering is the eyedropper tools in both the curves, and levels adjustmen

  • Recovery of photos

    Please Help!!! I deleted some files from my iphotos thinking I had them saved in other places.. facebook, on my phone but it has deleted them everywhere. Anything I can do to get them back?

  • LSMW - Upload purchase contracts (ME31K) with BAPI

    I'm trying to upload some contracts from the legacy to SAP ECC 6.0 using LSMW. I've already worked with Direct Input and Batch Input record with LSMW but never with BAPI. I found business object BUS2014 / Message Type - PURCONTRACT_CREATE but I don't

  • Custom tree node

    Hi I need to create a custom tree. Is it posible in flex tree, to have a node, that is a panel component, with a few other components, like textinput or buttons? Clicking on buttons causes adding or removing new nodes in appropriate place in the tree