java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jlazala24
    New Member
    • Nov 2006
    • 1

    #1

    java

    Thisn is my HW
    Write a program that prompts the user to enter five scores and then prints the average test score... Can someone help start this programming. I'm new with java
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by jlazala24
    Thisn is my HW
    Write a program that prompts the user to enter five scores and then prints the average test score... Can someone help start this programming. I'm new with java
    You know that you're only going to be getting 5 scores, so I would use a for loop to iterate over your variables and inputs.

    here's a link on reading data in:


    and here's one on loops:


    If you have any more questions, post whatever code you have, and whatever error messages you get, and we'll do what we can to help.

    Comment

    • roshancaptain1
      New Member
      • Oct 2006
      • 14

      #3
      Use a scanner:
      import java.util.Scann er;
      class prompt2 {
      public static void main(String[] args)
      throws java.io.IOExcep tion {
      Scanner scan = new Scanner(System. in);
      int p[] = new int[4];
      int avg[]=0;
      for ( int i = 0; i < 6; i++) {
      System.out.prin t("Enter the values " + i + " :");
      p[i] = scan.nextInt() ;
      avg1[]=avg+p[i];
      System.out.prin tln();
      }
      int avg[];
      avg=avg1/5;
      System.out.prin tln("the average: " +avg);
      }
      }

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by roshancaptain1
        Use a scanner:
        import java.util.Scann er;
        class prompt2 {
        public static void main(String[] args)
        throws java.io.IOExcep tion {
        Scanner scan = new Scanner(System. in);
        int p[] = new int[4];
        int avg[]=0;
        for ( int i = 0; i < 6; i++) {
        System.out.prin t("Enter the values " + i + " :");
        p[i] = scan.nextInt() ;
        avg1[]=avg+p[i];
        System.out.prin tln();
        }
        int avg[];
        avg=avg1/5;
        System.out.prin tln("the average: " +avg);
        }
        }
        We prefer to let people attempt their problems first before dumping solutions on them. Now your code doesn't even compile. If you want to help people just check to see that your suggestions are correct first before posting them.

        Comment

        Working...