0

I'm trying to get the highest and lowest number entered by user. I got this. I just new in programming. There are 3 errors.

import java.io.*;
public class HighestToLowest
{
    public static void main(String []args)throws IOException{
    {
        BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));        

        double[] input = new double[8];
        int index;
        int highIndex = 0;
        int lowIndex = 0;
        double sum = 0;

        System.out.println("Enter The Scores Of Judges: ");
        for (index = 0; index<8; index++){
             System.out.print("Enter The Score" + (index + 1) + ": ");
             input[index] = Double.parseDouble(dataIn.readLine()); 
         }

         for (index = 1; index < 8; index++)
             if(input[highIndex] < input[index])
                highIndex = index;


         for (index = 1; index < 8; index++)
             if (input[lowIndex] > input[index])
                 lowIndex = index;

         for (index = 0; index < 8; index++)
             sum = sum + input[index];
         try
            {
                input[index] = Double.parseDouble(dataIn.readLine());
            }
            catch(IOException e)
            {
                System.out.println("error");
            }

            if(sum>index)
            {
                sum=highIndex;
            }

            if(sum>=index)
            {
                index=lowIndex;
            }                        
        }

        System.out.print("Highest is: + highIndex");
        System.out.print("Lowest is: + lowIndex");

         System.out.printf("The Contestant Receives a total of %.2f", (sum - highIndex - lowIndex)); 



    }
}
6
  • 7
    What are the errors ? Commented Mar 16, 2011 at 16:50
  • 4
    Whenever you have error messages, always post the line giving you the problem and the complete message. Commented Mar 16, 2011 at 16:50
  • 3
    Next time, try putting the question in the "body" of the question and not the "title". Commented Mar 16, 2011 at 16:50
  • 9
    Hey guys, let's be a bit nicer to a newcomer and not close his first post immediately, without even allowing him some time to fix it. Commenting on the issues are fine, closing is not. Commented Mar 16, 2011 at 16:52
  • @Peter, 8 revisions in less than 8 minutes means a fairly rough start. Commented Mar 16, 2011 at 16:57

1 Answer 1

1

Although you say there are only 3 errors, there seen to be a bit more

public static void main(String []args)throws IOException{ //<- ?
{//<- why two curly brackets?

In for loop

for (index = 0; index < 8; index++){//<- curl bracket missing?
         sum = sum + input[index];
         try {
              input[index] = Double.parseDouble(dataIn.readLine());
          } catch(IOException e) {
              e.printStackTrace();
         }

         if(sum>index) {
              sum=highIndex;
          }
          if(sum>=index){
              index=lowIndex;
           }                        
     } // <- or extra curl bracket?

This line will print Highest is: + highIndex

  System.out.print("Highest is: + highIndex");

Any thing in " " is printed as it is.

So change it to

 System.out.print("Highest is:" + highIndex);

Same applies for

  System.out.print("Lowest is: + lowIndex");

Are you from C programming, this line is correct

System.out.printf("The Contestant Receives a total of %.2f", (sum - highIndex - lowIndex)); 

In Java it can also be written as

 System.out.println("The Contestant Receives a total of " +  (sum - highIndex - lowIndex));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.