File and bubble sort problem

hey, I'm in a bit of a pickle.
I'm trying to read from a file then bubble sort the file then write that to another file. Any suggestions how I can go about this. I've managed to read from the file, but have no idea how to bubble sort it.
Any useful suggestions would be appreaciated

Find the code below to read the numbers from nonsorted.txt frile in d: Drive and outputs the sorted into sorted.txt
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class BubbleSort {
     static StringBuffer newFile;
     static String FileNamewithpath = "d:/nonsorted.txt";
     static String NewFileNamewithpath = "d:/sorted.txt";
     static ArrayList numberList;
      * @param args
          public static void main(String args[]) {
               newFile = new StringBuffer();
               numberList = new ArrayList<Integer>();
               try {
                    FileInputStream fstream = new FileInputStream(FileNamewithpath);
                    DataInputStream in = new DataInputStream(fstream);
                    StringBuffer sb = new StringBuffer();
                    // there are still some left to read
                    while (in.available() != 0) {
                         getNumbers(in.readLine());
                    in.close();
                    System.out.println(numberList);
                    numberList =  bubbleSortElements(numberList);
                    for (int i =0; i< numberList.size(); i++) {
                         newFile.append(Integer.parseInt(""+numberList.get(i)) + " ");
                    FileOut();
               } catch (Exception e) {
                    e.printStackTrace();
                    System.err.println("File input error");
          public static void getNumbers(String str) {
               StringTokenizer st = new StringTokenizer(str);
               int i =0;
               while (st.hasMoreTokens()) {
                    String word = st.nextToken();
                    numberList.add(word);
                    i++;
               //return null;
          public static void FileOut() {
               FileOutputStream out; // declare a file output object
               PrintStream p; // declare a print stream object
               try {
                    out = new FileOutputStream(NewFileNamewithpath);
                    p = new PrintStream(out);
                    p.println(newFile);
                    p.close();
               } catch (Exception e) {
                    System.err.println("Error writing to file");
     public static  ArrayList bubbleSortElements(ArrayList numList ){
     try {
          int tmp;
          for (int i=0; i<numList.size()-1; i++) {
                 for (int j=0; j<numList.size()-1-i; j++)
                   if (Integer.parseInt(""+numList.get(j+1)) < Integer.parseInt(""+numList.get(j))) {  /* compare the two neighbors */
                     tmp = Integer.parseInt(""+numList.get(j));         /* swap a[j] and a[j+1]      */
                     numList.set(j,numList.get(j+1));
                     numList.set(j+1,tmp);
     } catch(Exception e) {
          e.printStackTrace();
          return numList;
}

Similar Messages

  • Reading through a text file and then sorting

    I'm having a lot of problems with this.
    I have to read through a text file and I have to split the string up so that it is seperated into individual tokens. A line from the text file looks like this. addEvent(new Bell(tm + 9000)). I have to grab the addEvent, new, Bell, tm and 9000 and store it in a linkedlist. After reading through the whole text file I have to sort the the linked list based on the number. ie: 9000. Is there any way to do this? I currently break up the text file using a StringTokenizer object but then i am uncertain on how to add it to a linked list and then sort each line based on the number. Any help would be appreciated.
    Joe

    Sorry to bother you Ben but I just can't get my head wrapped around this. Here is exactly what I have to do:
    After reading, Events must be stored in the EventSet according to the time they are to occur. Assume that no time number is more than 8 digits long. Restart() must be able to deal appropriately with any order of the Events. To accomplish this have Restart() save the relevant Event information in an LinkedList of strings and sort the Events by time before adding each event to EventSet. Use the <list>.add() to set up your linked list. This is shown in c09:List1.java and Collections.sort(<list>) shown in c09:ListSortSearch. Modify the Bell() to output a single "Bing!". When you read in a Bell event generate the appropriate number of Bell events as indicated by rings. These must be set to the correct times. This is an alternative to generating the new Bell events within Bell(). It will allow them be sorted into their correct time sequence. At this point the output of the program should be identical the original program.
    After the intitial start, when restarting Restart() must provide to the user the option to recreate the EventSet from the linked list or read in a new file (supplied by the user). This must be achieved by prompting the user at the console. Please also allow the user the option to quit the program at this stage.
    Main Program Code:
    public class GreenhouseControls extends Controller
    private boolean light = false;
    private boolean water = false;
    private String thermostat = "Day";
    private boolean fans = false;
         private class FansOn extends Event
              public FansOn(long eventTime)
                   super(eventTime);
              public void action()
              // Put hardware control code here to
              // physically turn on the Fans.
              fans = true;
              public String description()
                   return "Fan is On";
         private class FansOff extends Event
              public FansOff(long eventTime)
                   super(eventTime);
              public void action()
              // Put hardware control code here to
              // physically turn off the Fans.
              fans = false;
              public String description()
                   return "Fans are Off";
         private class LightOn extends Event
              public LightOn(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here to
                   // physically turn on the light.
                   light = true;
              public String description()
                   return "Light is on";
         private class LightOff extends Event
              public LightOff(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here to
                   // physically turn off the light.
                   light = false;
              public String description()
                   return "Light is off";
         private class WaterOn extends Event
              public WaterOn(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   water = true;
              public String description()
                   return "Greenhouse water is on";
         private class WaterOff extends Event
              public WaterOff(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   water = false;
              public String description()
                   return "Greenhouse water is off";
         private class ThermostatNight extends Event
              public ThermostatNight(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   thermostat = "Night";
              public String description()
                   return "Thermostat on night setting";
         private class ThermostatDay extends Event
              public ThermostatDay(long eventTime)
                   super(eventTime);
              public void action()
                   // Put hardware control code here
                   thermostat = "Day";
              public String description()
                   return "Thermostat on day setting";
         // An example of an action() that inserts a
         // new one of itself into the event list:
         private int rings;
         private class Bell extends Event
              public Bell(long eventTime)
                   super(eventTime);
              public void action()
                   // Ring every 2 seconds, 'rings' times:
                   System.out.println("Bing!");
                   if(--rings > 0)
              addEvent(new Bell(System.currentTimeMillis() + 2000));
              public String description()
                   return "Ring bell";
         private class Restart extends Event
              public Restart(long eventTime)
                   super(eventTime);
              public void action()      
                   long tm = System.currentTimeMillis();
                   // Instead of hard-wiring, you could parse
                   // configuration information from a text
                   // file here:
              try
              BufferedReader in = new BufferedReader(new FileReader("Event Config.txt"));
              String str;
                   String[] l1 = new String[5];
                   LinkedList l2 = new LinkedList();
              while((str = in.readLine()) != null )
                        StringTokenizer st = new StringTokenizer(str, "(+); ");
                        int nIndex = 0;
                        while (st.hasMoreTokens())
                             l1[nIndex] = st.nextToken();
                        //System.out.println(st.nextToken());
                             nIndex++;
                        l2.add(l1);
                   String[] s1 = (String[])l2.get(1);
                   for(int i = 0; i < s1.length; i++)
                        System.out.println(s1);
                   Comparator comp = s1[4];
                   Collections.sort(l2, comp);
              in.close();
              catch (IOException e)
    rings = 5;
    addEvent(new ThermostatNight(tm));
    addEvent(new LightOn(tm + 1000));
    addEvent(new LightOff(tm + 2000));
    addEvent(new WaterOn(tm + 3000));
    addEvent(new WaterOff(tm + 8000));
    addEvent(new Bell(tm + 9000));
    addEvent(new ThermostatDay(tm + 10000));
    // Can even add a Restart object!
    addEvent(new Restart(tm + 20000));*/
    public String description() {
    return "Restarting system";
    public static void main(String[] args) {
    GreenhouseControls gc =
    new GreenhouseControls();
    long tm = System.currentTimeMillis();
    gc.addEvent(gc.new Restart(tm));
    gc.run();
    } ///:~
    Examples File:
    addEvent(new ThermostatNight(tm));
    addEvent(new Bell(tm + 9000));
    addEvent(new Restart(tm + 20000));
    addEvent(new LightOn(tm + 1000));
    addEvent(new WaterOn(tm + 3000));
    rings = 5;
    addEvent(new FansOn(tm + 4000));
    addEvent(new LightOff(tm + 2000));
    addEvent(new FansOff(tm + 6000));
    addEvent(new WaterOff(tm + 8000));
    addEvent(new WindowMalfunction(tm + 15000));
    addEvent(new ThermostatDay(tm + 10000));
    EventSet.java Code:
    // This is just a way to hold Event objects.
    class EventSet {
    private Event[] events = new Event[100];
    private int index = 0;
    private int next = 0;
    public void add(Event e) {
    if(index >= events.length)
    return; // (In real life, throw exception)
    events[index++] = e;
    public Event getNext() {
    boolean looped = false;
    int start = next;
    do {
    next = (next + 1) % events.length;
    // See if it has looped to the beginning:
    if(start == next) looped = true;
    // If it loops past start, the list
    // is empty:
    if((next == (start + 1) % events.length)
    && looped)
    return null;
    } while(events[next] == null);
    return events[next];
    public void removeCurrent() {
    events[next] = null;
    public class Controller {
    private EventSet es = new EventSet();
    public void addEvent(Event c) { es.add(c); }
    public void run() {
    Event e;
    while((e = es.getNext()) != null) {
    if(e.ready()) {
    e.action();
    System.out.println(e.description());
    es.removeCurrent();
    } ///:~
    Event.java Code
    abstract public class Event {
    private long evtTime;
    public Event(long eventTime) {
    evtTime = eventTime;
    public boolean ready() {
    return System.currentTimeMillis() >= evtTime;
    abstract public void action();
    abstract public String description();
    } ///:~
    Is this problem easier than I think it is? I just don't know what to add to the linkedList. A LinkedList within a linkedList? I find this problem pretty difficult. Any help is muchly appreciated.
    Joe

  • File Name Changes, Sorting Problem

    Hi,
    iTunes 10.5.1
    MacBook Pro Snow Leopard
    I am attempting to add a series of lectures to iTunes. These number about 100 and are sequential over 3 volumes. I obtained them in simple forlders labeled vol1, vol2 and vol3 and each track is named with a prefix such as "V1 Ch03 Relation of Physics to other Sciences.mp3". Oddly about half actually retain the full name and sort out properly but the rest do not. For instance the example in question becomes " Relation of Physics to other Sciences.mp3" and not sorting tricks can get them in order.
    Before I starting fooling with the names is there somethign else I can do? I have turned off "automatically check for track names" option on iTunes but the same result. Are the spaces causing problems? I don't want to change the names as I would like to share these and others won't figure out the sequence.
    There doesn't seem to be an option for date created sorting which may solve the issue. Also iTunes seems to be reading some meta data as the "album name" changes. It seems the lectures were originally released in a different series and recently compiled in the order created, the latter being preferrable.
    Any help appreciated!
    Happy Holidays!
    Warren

    Oops, Just realised I put this n the wrong forum. Just to clarify this is prerecorded video files.

  • Multidimensional Array and Bubble Sorting

    Goal:
    Bubble sort the array. I want to keep the data organized. So, 70 with aa, 20 with cc, 40 with ee and so foth.
    Example output....
    aa 70
    bb 30
    cc 40
    dd 90
    then..... by number
    ee 10
    cc 20
    bb 30
    ee 40
    Problem:
    I dont know how to bubble sort by letters. AND, a big and..., and I have not done a double array like this. (can you tell?) :)
    package bubleexample;
    public class BubbleSort
         public BubbleSort ()
         public void sortIntArray (int []  pIntArr)
              int     cnt;
              int     tmp = -1;
              for (int a = 0; a < pIntArr.length - 1; a++)
                   for (cnt = 0; cnt < pIntArr.length - 1; cnt++)
                        if (pIntArr [cnt] > pIntArr [cnt + 1])
                             tmp = pIntArr [cnt];
                             pIntArr [cnt] = pIntArr [cnt + 1];
                             pIntArr [cnt + 1] = tmp;
         public void displayArray (int [] pIntArray)
              for (int cnt = 0; cnt < pIntArray.length; cnt++)
                   System.out.println ("Array[" + cnt + "]: " + pIntArray [cnt]);
         public static void main (String []  args)
              int []  myNumberList = { 70, 20, 40, 10, 80, 60, 30 , 50, 30, 90 };
            String [] myLetterList = { "aa", "cc", "ee", "xx", "bb", "tt", "gg", "rr", "jj", "dd" };
              BubbleSort sortIntArray = new BubbleSort ();
              System.out.println ("Before Sorting");
              sortIntArray.displayArray (myNumberList);
            //sortStringtArray.displayArray (myLetterList);
              sortIntArray.sortIntArray (myNumberList);
            //sortStringArray.sortStringArray (myLetterList);
              System.out.println ("\nAfter Sorting");
              sortIntArray.displayArray (myNumberList);
            //sortStringArray.displayArray (myLetterList);
              System.exit (0);
    }If something is unclear, please let me know.

    incomplete example:
    class Movie
         private String name;
         private int rating;
         public Movie( String name, int rating )
              this.name = name;
              this.rating = rating;
         public String getName() { ..... }
         public int getRating() { ...... }
         public String toString() {} // recommended but you don't have to
    } // end of class Movie
    public class SortString2
         public static sort(..) {...}
         public static void main( String args[] )
              String[] names = {"Meet the Fockers","Blade",...};
              int[] ratings = {5,3,4,...}
              Movie[] movies = makeMovieArray( names, ratings );
              sort( movies );
              System.out.println(...);
              for ( Movie movie : movies )
                   System.out.printf( "movie:  %s\nrating:  %d\n\n", movie.getName(), movie.getRating() );
         public static Movie[] makeMovieArray( String[] names, int[] ratings )
              Movie[] movies;
              if ( names.length == ratings.length )
                   movies = new Movie[names.length];
                   for ( int i=0; i<names.length; i++ )
                        movies[i] = new Movie(names,ratings[i]);
                   return movies;
              else
                   return;
    } // end of class SortString2                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • File and Printer Sharing problem

    Message Edited by bartman_60042 on 11-13-2007 05:47 AM

    Oops...somehow submitted without any text.
    My set-up: Linksys Cable Modem with Linksys Wireless Router.  2 Desktop Computers (Black and Grey) and 1 Laptop.  Windows XP SP2 with all current upgrades on each.
    While setting up File and Printer Sharing, I have the following:
    1) The Black computer can file/printer share from both the Grey computer and Laptop.
    2) The Grey computer can only file/printer share from the Laptop; not from the Black computer.
    3) The Laptop can only file/printer share from the Grey computer; not from the Black computer.
    All 3 computers were configured the same as far as I can tell.  The only difference I notice is that the Black computer boots without the XP 'login' screen (no password required), could this be causing the problem?  If this is the issue, how would I change the settings to 'login' to the Black computer?  Any thing else which may be wrong?

  • File and Printer Sharing Problem with WRT54G

    I am currently having problems sharing files over my network. My setup consists of:
    3 laptops (wireless)
    1 desktop (wired)
    WRT54G V6.0 router with firmware version 1.00.9.
    All of the computers have File and Printer Sharing enabled, unique names, and are on the same workgroup. However none of the computers can see one another. When I try to view workgroup computers for my network places, the explorer window stops responding for about 30 sec. and then spits out a dialog with the error:
    "Workgroup is not accessable. You might not have permission to use this network resource. Contact the administrator of this server to find out if you have access permissions.
    The list of servers for this workgroup is not currently available."
    I think that this problem has something to do with the router, as I have been successfuly sharing files and a printer with these settings using a microsoft 802.11b router for over a year. After purchasing the linksys and swapping it out with my old router, filesharing no longer functions.
    I have spent a little time browsing the forums and have seen other posts from people with simmiler problems, but was unable to find any solutions.
    Any help would be much appreciated.
    Thanks.

    I'm having the same problems as you are, I have 2 computers on wired the other wireless the router is in between and I can't access from either side, although I can ping and remote connect but just cannot share files across the network. I have looked all over the forums too and there saying to ditch linksys and do something else.
    Its not you thats caused this it is the firmware and the router that have the problems.
    My Specs:
    WRT-54G
    v5.0
    That new firmware update 1.00.9 just isn't working right. I might downgrade my fireware to fix this problem.
    Message Edited by justin2006 on 09-26-200612:24 PM

  • Creative Cloud files and fonts sync problem

    Hi
    I'm working on two diffents mac's, one at work and one at home - with a creative cloud membership. On both computers, the Files and Fonts does not connected/sync. Annyway, I can't use the fonts on either of the mashines. The CC app is open, and therefor should work with e.g. the fonts I allready synced to my computer . Apparently I can solve this by quiting the Creative Cloud and restart, but I hope this could be solved somehow.
    Anyone have an idea or a way forward?
    Jørgen

    Hi Dave
    It seams to be working now on both computers, after the last update - thanks!
    Just arrived home, and my home computer Creative Cloud connection is not working as it should for Files and Typekit. I'm not getting any error messages - it just doesn't  connect i seams. I include some screenshots - but I don't think they will say much. It is as if there is some problem when it is trying to load/connect while other programes are auto loading (I guess?). So I still need help. Here is some screenshots. I can still restart the CC and then it connects as it should. And, I have the same problem on an other mac:
    Jørgen

  • Urgent ! BPEL file and ftp adapter problem.

    Hi All!
    I have created a bpel process having two partner links.One for the ftp adapter and one for the file adapter. I want the ftp adapter to poll the *.pdf files in the specified directory on the remote machine periodically and get them to my local machine here. For this I am using ftp adapter with read operation and with opaque schemas(because I want the files as they are without any transformation). I am using a receive activity with the ftp adapter, with the create instance box checked.
    To write the file to the local machine I am using file adapter and write operation.File adapter also uses opaque schema.With this file adapter I am using invoke activity.Invoke is below the receive activity in the bpel process. I deployed this successfully on the default domain. I want the bpel process to run automatically,depending on the polling frequency given and create instances and bring the files to my machine.
    But it is not happening.
    Can anybody tell me where I am going wrong.How to accomplish this? It is very urgent issue for me.
    Thanking in advance,
    Regards,
    Deepika.

    Hi All!
    Now I am able to write files and also read files successfully with the remote server. I followed the same method described above.I am using binary format itself for pdf files.But I have to check the option 'to delete files after successful retrieval' to make this happen.I created several partnerlinks with the option in the ftp adapter not checked,but it is not working. Has anybody done successful retrieval without deleting the files at the remote server? If so please let me know.
    Thanking in advance,
    Regards,
    Deepika.
    Message was edited by:
    Deepika

  • ID file and PDF export problem

    hi,
    hope someone can help me...
    i created a file in ID. you can see the specs here:
    http://cpso2.gallaudet.edu/cpso/brian/mw-bleed.jpg
    in the above image, you can see the bleed margin, and i made sure everything goes fully into the bleed.
    so then i sent the export (PDF) to the printer. see it here:
    http://cpso2.gallaudet.edu/cpso/brian/youth_savedate_final.pdf
    so here i am excited thinking i did this right. then the prrpress department comes back and tells me the following:
    "" I checked with my prepress dept. and they are telling me that the Document Setup that you are in will allow you to set your bleeds BUT will not hold the bleeds. You need to export and that will give you options to set bleeds. (This is a bit greek to me so if you have a problem, let me know and I will get her to converse directly with you).""
    I thought I did this right. Can someone tell me what I did wrong in export and how to remedy the problem?
    thanks - mike, the deaf guy.

    That's better.
    It makes sense, really; you might want to send a pdf of the file to
    the printers, who needs the bleed, and another of the same file to a
    colleague, who wouldn't thank you for all that extra stuff round the
    edges if he doesn't realize he can hide it in his reader. You
    wouldn't want the bleed and slug bits to show if you posted an
    'optimized for web' pdf on the web or emailed it to someone
    interested in your courses. You can thus create different pdfs for
    different purposes from the same .indd file.
    Noel

  • Yosemite and Mail sort problem

    Hi,
    I typically have a few-hundred items in my Mail inbox. Prior to upgrading to Yosemite, when I had an email highlighted and clicked either "From" or "Subject" Mail would sort all of the email by that corresponding field and jump down to all of the messages that fit that criteria.
    After the upgrade, I can still obviously sort, but for example, if I sort by name, the view doesn't "jump", meaning all the A's come to the top and I have to scroll down to find the highlighted message.
    This is a bit annoying and slows me down quite a bit in terms of productivity, ie reading all the messages from a particular person or from a particular chain.
    Does anyone know how to toggle this back?

    Have you gotten any replies, help, hints on this?  I have this problem, too, and it is really getting annoying.  I have professional mail folders with hundreds of messages and I used to heavily rely on the "sort but stay on this message" feature.  I just assumed that that's how every mail program works and how every mail program should work.

  • M files and exe build problems

    Hello,
    Pleae help because this has been driving me crazy!
    I am using a series of mathcript nodes to call up 4 x m files.  Those top level m files also calls up other m files.  But under the dependencies list of the Project Explorer, it only lists the 4 x top level m files.  Anyway, it all runs fine but when the exe is built and ran, it by passes the m files functions without any error report.
    When the exe is built are ALL the m files compiled or just the ones on the dependencies list?  Do I need to include the m files in the directory of the exe file?
    The run time engine has some unsupported mathscript functions, how do I find/filter out unsupport functions in the m files?
    Is there anything else I need to check to get the exe file working properly?

    I am sorry - I have not done much with mathscript nodes yet.
    I had a look in the Labview help and it says this:
    http://zone.ni.com/reference/en-XX/help/371361E-01/gmath/mathscript_node/
    "The LabVIEW Run-Time Engine does not support
    MathScript Nodes with warning glyphs. If a VI includes a MathScript
    Node with a warning glyph, you must remove the warning glyph from the
    MathScript Node before you build a stand-alone application or shared library.
    The LabVIEW Run-Time Engine also does not support certain MathScript
    functions. To include a MathScript Node in a stand-alone application or
    shared library, you might need to modify scripts that contain these unsupported functions."
     One of the things that causes the warning glyph is the use of include functions. So it seems you can't do this under the run-time.

  • N91's files and data sharing problem

    Guys i am newbie for this forum . i wanna say a big HI to every member of this forum. My query is that i have n91-8GB and when i try to transfer datas (large size like above 10 mb) from bluetooth, my phone memory becomes full and error message is displayed cz the file is directly transfered to inbox. So, is there any technique to change the folder to my memory card?
    Another query is that my phone is not able to synchronize with my pc and displays some error message everytime i try to synchronize it, so how will this prob will be solved? Hope for best replies... Thankx in advance

    Guys i am newbie for this forum . i wanna say a big HI to every member of this forum. My query is that i have n91-8GB and when i try to transfer datas (large size like above 10 mb) from bluetooth, my phone memory becomes full and error message is displayed cz the file is directly transfered to inbox. So, is there any technique to change the folder to my memory card?
    Another query is that my phone is not able to synchronize with my pc and displays some error message everytime i try to synchronize it, so how will this prob will be solved? Hope for best replies... Thankx in advance

  • Removed some files and... problem...

    Can I restore to a how my computer was a couple hours ago? I have proper backups done through TM. I did not keep track of all the files that were removed while I was uninstalling an application.

    I was able to fix the problem by re-installing an application...

  • Bubble sort problem:ArrayIndexOutOfBoundsException,

    I'm supposed to calculate most and least rainfall but my method goes out of bounds? I think mabey Its cause my count starts at zero...It was functioning before I switched out variables.It was not working accurately. After 4 hours Im stumpted.Am i overlooking something syntaxal of are my loops not logical? Thanks Stars!
    import java.util.Scanner;
    public class Rainfall2
       public static void main(String[]args)
               double []mrt = new double[12];  
                getRainfall(mrt);
                getAvgrainfall(mrt);
                getMonthMostrain(mrt);
                getMonthLeastrain(mrt);
        public  static void getRainfall(double []mrt)
              for (int i = 0; i < mrt.length; i++)
                  Scanner keyboard=new Scanner(System.in);
                  System.out.println("Input Monthy Rain Total for month #" +(i+1));
                 mrt=keyboard.nextInt();
              System.out.println(" Monthy Rain Total for month #" +(i+1)+ " is " +mrt[i] + " inches");
              if(mrt[i]<0)
              { System.out.println("Input Monthly Rain Total of Zero or greater!!!");
                   System.out.println("Input Monthy Rain Total for month #" +(i+1));
                   mrt[i]=keyboard.nextInt();
    public static void getAvgrainfall(double []mrt)
                   int month=0;
              double avg;
              avg=0.0;     
                             for (int i=0;i<mrt.length;i++)
                        avg=avg+mrt[i];
                        avg=avg/12;
                   System.out.println("Average rainfall is " + avg + " inches.");
                   public static void getMonthMostrain(double []mrt)
                        int rC=0;
                        double temp;
                        temp =mrt[0];
                   for (int i=0;i<12;i++)
                        if (mrt[i] >mrt[(i+1)])
                   temp =i;
                   System.out.println("The most rainfall fell in Month # "+ rC);
                   public static void getMonthLeastrain(double []mrt)
                        int rC=0;
                   for (int i = 0; i < 11; i++)
                             if (mrt[i] < mrt[i+1])
                        rC = i;
                        System.out.println("The least rainfall fell in Month # "+ rC);

    I changed the 12 to 11
    when values 1 to12 inches are entered it says
    The most rainfall fell in Month # 1
    The least rainfall fell in Month # 11
    when i enter 12 inches 11...10 to 1 it reads
    The most rainfall fell in Month # 1
    The least rainfall fell in Month # 1
    On top of that what if 2 rainfall months were the same or 0
    I guess theres supposed to be much more to this loop...
    Is it typical to have to work on this for 6 hours or does it depend on your
    apptitude for logic or something????Thanks again for your suggestions!
    import java.util.Scanner;
    public class Rainfall4
       public static void main(String[]args)
               double []mrt = new double[12];  
                getRainfall(mrt);
                getAvgrainfall(mrt);
                getMonthMostrain(mrt);
                getMonthLeastrain(mrt);
        public  static void getRainfall(double []mrt)
              for (int i = 0; i < mrt.length; i++)
                  Scanner keyboard=new Scanner(System.in);
                  System.out.println("Input Monthy Rain Total for month #" +(i+1));
                 mrt=keyboard.nextInt();
              System.out.println(" Monthy Rain Total for month #" +(i+1)+ " is " +mrt[i] + " inches");
              if(mrt[i]<0)
              { System.out.println("Input Monthly Rain Total of Zero or greater!!!");
                   System.out.println("Input Monthy Rain Total for month #" +(i+1));
                   mrt[i]=keyboard.nextInt();
    public static void getAvgrainfall(double []mrt)
                   int month=0;
              double avg;
              avg=0.0;     
                             for (int i=0;i<mrt.length;i++)
                        avg=avg+mrt[i];
                        avg=avg/12;
                   System.out.println("Average rainfall is " + avg + " inches.");
                   public static void getMonthMostrain(double []mrt)
                        int rC=0;
                        double temp;
                        temp =mrt[0];
                   for (int i=0;i<11;i++)// changed to 11
                        if (mrt[i] >mrt[(i+1)])
                   temp =i;
                   System.out.println("The most rainfall fell in Month # "+ (rC+1));//changed to rC +1
                   public static void getMonthLeastrain(double []mrt)
                        int rC=0;
                   for (int i = 0; i < 11; i++)
                             if (mrt[i] < mrt[i+1])
                        rC = i;
                        System.out.println("The least rainfall fell in Month # "+ (rC+1));//changed to rC+1

  • I have a problem with my mac  i have too many  archives and programs and i want to delete all files and start at the begin my mac with out do format

    i have a problem with my mac  i have too many  archives and programs and i want to delete all files and start at the begin my mac with out do format

    I do not recommend reformatting your harddrive and reloading your software.  This is a Windows thing. On an older mac it may be difficult to find all your software again.
    Best to have greater than 2gig of free space.  Many posters to these forums state that you need much more free space: 5 gig to 10 gig or 10 percent of you hd size.
    (0)
    Be careful when deleting files. A lot of people have trashed their system when deleting things. Place things in trash. Reboot & run your applications. Empty trash.
    Go after large files that you have created & know what they are.  Do not delete small files that are in a folder you do not know what the folder is for. Anything that is less than a megabyte is a small file these days.
    (1)
    Run
    OmniDiskSweeper
    "The simple, fast way to save disk space"
    OmniDiskSweeper is now free!
    http://www.omnigroup.com/applications/omnidisksweeper/download/
    This will give you a list of files and folders sorted by size. Go after things you know that are big.
    (2)
    These pages have some hints on freeing up space:
    http://thexlab.com/faqs/freeingspace.html
    http://www.macmaps.com/diskfull.html
    (3)
    Buy an external firewire harddrive.
    For a PPC computer, I recommend a firewire drive.
    Has everything interface:
    FireWire 800/400 + USB2, + eSATA 'Quad Interface'
    save a little money interface:
    FireWire 400 + USB 2.0
    This web page lists both external harddrive types. You may need to scroll to the right to see both.
    http://eshop.macsales.com/shop/firewire/1394/USB/EliteAL/eSATA_FW800_FW400_USB
    (4)
    Buy a flash card.

Maybe you are looking for

  • How to publish WSDL as Webservice in XI 3.0

    Hello, My Scenario is  SOAP --XI -- R/3(Proxy). XI version is XI 3.0 and SAP R/3 4.7 Generated a WSDL for SOAP Sender(ID>Tools>Define webservice) I want to know  how can i publish this  WSDL as webservice. Appericiate your help. Srinivas Edited by: S

  • What kind of server can host RMI

    I am trying to use RMI, however there are some simple question about the server type I want to ask. A. Is it possible to use a http server like www.myschoolurl.edu/~mypage? I can only access the root directory of ~mypage in a unix system. B. Can I us

  • Landscpae for BI7.0

    Friends, Need your advise urgently.Please help us with ur suggestions. We have installed SAP Netweaver 2004s in Dev server. Currently we are planning to create three clients in that server and do the client copy. client 222 for Dev client 333 for San

  • Digital input configuration

    Good Morning, I am trying to get the picks of a signal of variable frequence, that goes until 24 Hz. When I acquire with 1 sample on demand, I loose some picks. When I try to configure "N samples", it tells me to configure external clock, and when I

  • How do I get out of full screen?

    How can I get out of full screen and get my apple emblem and otehr at the top of the screen?