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 3 of 3

Thread: Using Arrays for the first time

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Using Arrays for the first time

    I recently began working with arrays and calling method statements and it appears that somewhere within this code I have made an error. The program is supposed to allow for the input of average temperatures for each day of the week and display them. Then it is supposed to display the highest, lowest and total average of the 7 values. I am able to have it display the inputs but I cannot get the days to automatically fill in as Mon, Tues...etc. Also, the additional methods to solve for highest, lowest, and average are not appearing in the output whatsoever. Any help would be greatly appreciated. Thanks in advance.

    import java.util.Scanner;
     
    public class Temperatures
    {
       public static void main(String[] args)
       {
          final int Day = 7;             
    		String[] name = {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};   
          int[] temp = new int[Day];        
     
          Scanner readName  = new Scanner(System.in);
    		Scanner readTemp  = new Scanner(System.in);
     
    		System.out.println("Enter both the day and the average temperature for that day.");
     
     
          for (int index = 0; index < Day; index++)
          {
             System.out.print("\nDay " + (index + 1) + ":  ");
    			name[index] = readName.nextLine();
     
    			System.out.print("Average Temp " + (index + 1) + ": ");
             temp[index] = readTemp.nextInt();
          }
     
          System.out.println("\nThe information you entered is:");
     
          // Display the values entered.
          for (int index = 0; index < Day; index++)
             System.out.printf("%-20s  %2d \n", name[index], temp[index]);
     
     
     
       }
     
    	public static int findHighest(int[] A)
    	{
    		int highest = A[0];
    		int size = A.length;
    			for (int i = 1; i < size; i++)
    			{
    				if (A[i] > highest)
    				highest = A[i];
     
    			System.out.println("The highest average temp is " + highest);
    			}
    		return highest;
    	}
     
    	public static int findLowest(int[] A)
    	{
    		int lowest = A[0];
    		int size = A.length;
    			for (int i = 1; i < size; i++)
    			{
    				if (A[i] < lowest)
    				lowest = A[i];
     
    			System.out.println("The lowest average temp is " + lowest);
    			}
    		return lowest;
    	}
     
    	public static int findAverage(int[] A)
    	{
    		int average = A[0];
    		int size = A.length;
    		average = (A[0]+A[1]+A[2]+A[3]+A[4]+A[5]+A[6])/size;
     
    		System.out.println("The average of all temps is " + average);
     
    		return average;
    	}
    }

    Output:

    Day 1: Monday
    Average Temp 1: 45

    Day 2: Tuesday
    Average Temp 2: 56

    Day 3: Wednesday
    Average Temp 3: 46

    Day 4: Thursday
    Average Temp 4: 48

    Day 5: Friday
    Average Temp 5: 42

    Day 6: Saturday
    Average Temp 6: 32

    Day 7: Sunday
    Average Temp 7: 37

    The information you entered is:
    Monday 45
    Tuesday 56
    Wednesday 46
    Thursday 48
    Friday 42
    Saturday 32
    Sunday 37


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,213
    Thanks
    52
    Thanked 2,294 Times in 2,265 Posts

    Default Re: Using Arrays for the first time

    Please post the program's output and add some comments saying what is wrong and show what the output should be.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: Using Arrays for the first time

    .

Similar Threads

  1. Replies: 0
    Last Post: January 28th, 2013, 04:29 AM
  2. Hello, first time caller long time programmer....
    By P2C2N in forum Member Introductions
    Replies: 3
    Last Post: December 10th, 2012, 10:53 AM
  3. Replies: 2
    Last Post: October 19th, 2012, 03:32 AM
  4. [SOLVED] Help with time
    By usama8800 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 25th, 2012, 04:13 PM
  5. [SOLVED] Faster Run Time - Scanner(file) and Arrays
    By Dogeatdog6 in forum What's Wrong With My Code?
    Replies: 13
    Last Post: April 7th, 2011, 09:25 AM