Sorting numbers from in an array...please help
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Sorting numbers from in an array...please help

  1. #1
    Join Date
    Oct 2013
    Posts
    1

    Sorting numbers from in an array...please help

    Ok The problem is that there are 20 grades inside an array. The answer is supposed to be a displayed by grade level is 85 >= A , <84 = B, <=75 =C. I can't get the program to excecute. I am trying to use an else if statement and it keeps coming up with errors please help! This is the program I have written. I know it may be a little sloppy, I am a beginner so any syntax help is also appreciated.

    public class problem2{
    public static void main (String []args){
    Scanner scan= new Scanner(System.in);
    int a []= new int [20];
    for (int k=0; k<20;k++)
    a[k] = scan.nextInt ();
    char b[]= new char[20];
    int x=0, y=0,z=0;
    for (int i=0; i<20;i++)
    int a[]= {90,91,93,94,95,84,82,81,86,87,73, 74, 75,76,77, 76, 71, 86, 87,88};

    {
    if a[i].=85)
    b[i]='A';
    else if((a[i]<84) && (a[i]>=75))
    else
    b[i]='B';

    else
    b[i]='C'
    }
    for (int j= 0;j<20;j++)
    if (b[j]=='A')
    {x++}
    else if (b[j]=='B')
    y++;
    else
    z++;
    }
    System.out.println("Number of students getting A = "+ x");
    System.out.println("Number of students getting A = "+ y");
    System.out.println("Number of students getting A = "+ z");
    }
    }
    }

  2. #2
    Join Date
    Sep 2013
    Location
    Chennai
    Posts
    5

    Re: Sorting numbers from in an array...please help

    I have tried from your problem statement.

    Try this..


    public class problem2 {
    public static void main(String[] args) {

    int a[] = { 90, 91, 93, 94, 95, 84, 82, 81, 86, 87, 73, 74, 75, 76, 77,
    76, 71, 86, 87, 88 };

    int gradeA = 0;
    int gradeB = 0;
    int gradeC = 0;

    for (int i = 0; i < a.length; i++) {
    if (a[i] >= 85) {
    gradeA++;
    } else if ((a[i] < 85) && (a[i] > 75)) {
    gradeB++;
    } else {
    gradeC++;
    }
    }

    System.out.println("Number of students getting A Grade = " + gradeA);
    System.out.println("Number of students getting B Grade = " + gradeB);
    System.out.println("Number of students getting C Grade = " + gradeC);
    }
    }

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center