Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Arrays nightmare

  1. #1
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Arrays nightmare

    Hi, I just don't seem to grasp arrays at all! So am continuing my practice in java.

    QUESTION:
    It's a radio poll on the most listened to radio station.
    I have to read the UNKNOWN number of integers from a file and output the percentage of all listeners that listen to each radio station.
    Each station has a unique code 1-5.

    It sounds pretty simple but not when I attempt to code it.

    Here is what I did:
    import java.util.*;
    import java.io.*;
     
    public class RadioStationsPoll{
             public static void main (String [] args) throw IOException{
             Scanner in = new Scanner (new FileReader("polls.txt"));
     
             int [] allStationCodes = new int [];
             int stationCode , i, total;
             int [] stationCount = new int [];
     
             stationCode = in.nextInt();
     
             while (stationCode !=0)
             {
     
                    for (int i = 1; i < 5; i++) 
    	        {
     
                              if (stationCode [i] == i)
                              {
                                   stationCount[i] = (stationCode[i]) ++;
                              }
     
                              total = total + count [i]++;
                              System.out.printf ("Station" +  i  + "%d     percent"  + stationCount [i] /total);
                              i++;
                    }
     
             }
     
       }   
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,592
    Thanks
    50
    Thanked 2,235 Times in 2,207 Posts

    Default Re: Arrays nightmare

    Can you explain what the problem is with the code you have posted? Be specific and show the program's output and explain what is wrong with the output.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Apr 2012
    Posts
    161
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: Arrays nightmare

    What exactly are you looking for as a result? Also, what have you gotten so far as a result?

  4. #4
    Member
    Join Date
    Mar 2014
    Posts
    92
    My Mood
    Inspired
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Default Re: Arrays nightmare

    Hey guys, I eventually got it to work, thanks tho

Similar Threads

  1. Help with arrays
    By Lasers in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 23rd, 2013, 11:24 PM
  2. Hello! parallel vectors nightmare
    By speaker in forum Collections and Generics
    Replies: 2
    Last Post: May 18th, 2012, 02:12 PM
  3. Need help using Arrays!
    By asb23698 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2012, 05:47 PM
  4. JTrees are a nightmare!
    By Danjb in forum AWT / Java Swing
    Replies: 3
    Last Post: July 4th, 2011, 07:43 AM
  5. 2d arrays help
    By gonfreecks in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 27th, 2010, 04:27 PM