Please look at the code below and follow with my questions:

import java.util.Scanner;

public class CaseGrade {

    public static void main(String[] args) {
        Scanner input =  new Scanner (System.in);
        String name = null ;
        int grade = 0;
        String exellent = "Exellent :";
        String veryGgood ="Very Good :";
        String good="Good :";
        String pass ="Pass :";
        String fail = "Fail :";
        String maxi = null;
        String mini =null ;
        String upAvg ="" ;
        String dwnAvg ="" ;


        int max = 0;
        int min = 100;
        int sum = 0;
        int avg  ;
        int counter =0;

        boolean repeat ;

        while (repeat =true)
        {
            System.out.println("Enter Name : ");
            name =  input.next();
            System.out.println("Enter Grade : ");
            grade = input.nextInt();

            switch (grade/10)
                {
                case 100:
                case 9 :
                    exellent += "\n"+ name + "\t" +grade+"\n";
                    break;
                case 8 :
                    veryGgood += "\n" + name + "\t" +grade +"\n";   
                    break ;     
                case 7 :
                    good += "\n" + name + "\t" +grade +"\n";    
                    break;
                case 6:
                case 5:
                    pass += "\n" + name + "\t" +grade +"\n";
                    break;
                    default:
                        fail +="\n" + name + "\t" +grade +"\n";
                    break;
                }

                sum = sum + grade;
                counter = counter + 1;

                if (grade > max) 
                {
                    max = grade;
                    maxi=name;
                }

                if (grade < min)
                {
                    min = grade;
                    mini= name;
                }


                if (grade == -1 )
                {   
                    //avg= (sum+1) /(counter-1);
                    avg= sum /counter;

                    if (grade >=avg)
                    {
                        upAvg += name+"\n";
                    }
                    if(grade<avg)
                    {
                        dwnAvg += name +"\n";
                    }


                    System.out.println(" result = :");
                    System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
                    System.out.println("maximum = "+ max +"\t" +maxi);
                    System.out.println("minimum = "+ min +"\t"+mini);
                    System.out.println("\tAverage = " +avg);

                    System.out.println("counter : "+counter);
                    System.out.println("sum :"+sum);
                    System.out.println("ubove avg\n"+upAvg +"\n");
                    System.out.println("under avg\n"+dwnAvg+"\n");
                    System.exit(0);
                }

            }




    }

}

i need to Print the names with the highest average and less than the average

Edited 3 Years Ago by Reverend Jim: Fixed formatting

look i try this with out name using array ..?

import java.util.Scanner;
public class ArrayEx {

    public static void main(String[] args) {

         int array[] = new int [10];
        Scanner input = new Scanner(System.in);

        String upAvg ="" ;
        String dwnAvg ="" ;
        int sum=0;
        int avg;

                for ( int j = 0; j< array.length; j++ )
                {

                    System.out.println("enter number :");
                    array[j]=input.nextInt();
                    sum=sum+array[j];
                }
                avg= sum/array.length ;
                for (int j=0 ; j<array.length ; j++)
                {
                    if(array[j]>avg)
                    {
                        upAvg += array[j]+"\n"; 
                    }
                    else if (array[j]<avg)
                    {
                        dwnAvg += array[j]+"\n";    

                    }
                    //System.out.println("value"+ array[j]);
                }
                System.out.println("avg =" +avg);

                System.out.println("ubove avg\n"+upAvg +"\n");
                System.out.println("under avg\n"+dwnAvg+"\n");
    }

}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

now still how to make it continue entering names and numner
and stop if entered some thing like -1 ,"Q" to exit


Help with Code Tags
Java Syntax (Toggle Plain Text)

1.
import java.util.Scanner;
2.
public class ArrayEx {
3.

4.
public static void main(String[] args) {
5.

6.
int array[] = new int [5];
7.
Scanner input = new Scanner(System.in);
8.
String []name = new String [5] ;
9.
String upAvg ="" ;
10.
String dwnAvg ="" ;
11.
String exellent = "Exellent :";
12.
String veryGgood ="Very Good :";
13.
String good="Good :";
14.
String pass ="Pass :";
15.
String fail = "Fail :";
16.
int sum=0;
17.
int avg;
18.
int min = array[0]=100;
19.
int max = array[0]=0;
20.
String maxi = null;
21.
String mini =null ;
22.

23.
for ( int j = 0; j< array.length; j++ )
24.
{
25.
System.out.println("enter name :");
26.
name[j]=input.next();
27.

28.
System.out.println("enter number :");
29.
array[j]=input.nextInt();
30.

31.
sum=sum+array[j];
32.

33.
if (array[j] > max)
34.
{
35.
max = array[j];
36.
maxi=name[j];
37.
}
38.

39.
if (array[j] < min)
40.
{
41.
min = array[j];
42.
mini= name[j];
43.
}
44.

45.
}
46.
avg= sum/array.length ;
47.
for (int j=0 ; j<array.length ; j++)
48.
{
49.
switch (array[j]/10)
50.
{
51.
case 100:
52.
case 9 :
53.
exellent += "\n"+ name[j] + "\t" +array[j]+"\n";
54.
break;
55.
case 8 :
56.
veryGgood += "\n" + name[j] + "\t" +array[j] +"\n";
57.
break ;
58.
case 7 :
59.
good += "\n" + name[j] + "\t" +array[j] +"\n";
60.
break;
61.
case 6:
62.
case 5:
63.
pass += "\n" + name[j] + "\t" +array[j] +"\n";
64.
break;
65.
default:
66.
fail +="\n" + name[j] + "\t" +array[j] +"\n";
67.
break;
68.
}
69.

70.
if(array[j]>avg)
71.
{
72.
upAvg += name[j] +"\t"+ array[j]+"\n";
73.
}
74.
else if (array[j]<avg)
75.
{
76.
dwnAvg += name[j] +"\t"+ array[j]+"\n";
77.

78.
}
79.
System.out.println("value=\t"+ array[j]);
80.
}
81.

82.
System.out.println(" result = :");
83.
System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
84.
System.out.println("maximum = "+ max +"\t" +maxi);
85.
System.out.println("minimum = "+ min +"\t"+mini);
86.

87.
System.out.println("avg =" +avg);
88.

89.
System.out.println("ubove avg\n"+upAvg +"\n");
90.
System.out.println("under avg\n"+dwnAvg+"\n");
91.

92.
}
93.

94.
}

import java.util.Scanner;
public class ArrayEx {

    public static void main(String[] args) {

         int array[] = new int [5];
        Scanner input = new Scanner(System.in);
        String []name = new String [5] ;
        String upAvg ="" ;
        String dwnAvg ="" ;
        String exellent = "Exellent :";
        String veryGgood ="Very Good :";
        String good="Good :";
        String pass ="Pass :";
        String fail = "Fail :";
        int sum=0;
        int avg;
        int min = array[0]=100;
        int max = array[0]=0;
        String maxi = null;
        String mini =null ;

                for ( int j = 0; j< array.length; j++ )
                {
                    System.out.println("enter name :");
                    name[j]=input.next();

                    System.out.println("enter number :");
                    array[j]=input.nextInt();

                    sum=sum+array[j];

                    if (array[j] > max) 
                    {
                        max = array[j];
                        maxi=name[j];
                    }

                    if (array[j] < min)
                    {
                        min = array[j];
                        mini= name[j];
                    }

                }
                avg= sum/array.length ;
                for (int j=0 ; j<array.length ; j++)
                {
                    switch (array[j]/10)
                    {
                    case 100:
                    case 9 :
                        exellent += "\n"+ name[j] + "\t" +array[j]+"\n";
                        break;
                    case 8 :
                        veryGgood += "\n" + name[j] + "\t" +array[j] +"\n"; 
                        break ;     
                    case 7 :
                        good += "\n" + name[j] + "\t" +array[j] +"\n";  
                        break;
                    case 6:
                    case 5:
                        pass += "\n" + name[j] + "\t" +array[j] +"\n";
                        break;
                        default:
                            fail +="\n" + name[j] + "\t" +array[j] +"\n";
                        break;
                    }

                    if(array[j]>avg)
                    {
                        upAvg += name[j] +"\t"+ array[j]+"\n";  
                    }
                    else if (array[j]<avg)
                    {
                        dwnAvg += name[j] +"\t"+ array[j]+"\n"; 

                    }
                    System.out.println("value=\t"+ array[j]);
                }

                System.out.println(" result = :");
                System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
                System.out.println("maximum = "+ max +"\t" +maxi);
                System.out.println("minimum = "+ min +"\t"+mini);

                System.out.println("avg =" +avg);

                System.out.println("ubove avg\n"+upAvg +"\n");
                System.out.println("under avg\n"+dwnAvg+"\n");

    }

}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Your thread is nearly unreadable. Please use code tags to post code.

click the code button in the editor and put your code between the opening and closing code tags that it inserts into your post.

Edited 7 Years Ago by donaldw: n/a

I've given up. The OP hasn't even asked a question, yet. And, considering the line numbers in one of the above posts, seems to be copying the code from elsewhere on this forum, so I see no point in continuing.

thanks i use code tags to post this

import java.util.Scanner;
public class ArrayEx {

	public static void main(String[] args) {
		int num_of_student ;
		
		Scanner input = new Scanner(System.in);
		System.out.println("Enter the  number of Student :");
		num_of_student = input.nextInt();
		
		
		String []name = new String [num_of_student] ;
		int array[] = new int [num_of_student];
		
		String upAvg ="" ;
		String dwnAvg ="" ;
		String exellent = "Exellent :";
		String veryGgood ="Very Good :";
		String good="Good :";
		String pass ="Pass :";
		String fail = "Fail :";
		int sum=0;
		int avg;
		int min = array[0]=100;
		int max = array[0]=0;
		String maxi = null;
		String mini =null ;
		
		
		
		        for ( int j = 0; j< array.length; j++ )
		        {
		        	System.out.println("Enter Student Name :");
		        	name[j]=input.next();
		        	
		        	System.out.println("Enter Student Grade :");
		        	array[j]=input.nextInt();
		        	
		        	sum=sum+array[j];
		        	
		        	if (array[j] > max) 
					{
						max = array[j];
						maxi=name[j];
					}
				
					if (array[j] < min)
					{
						min = array[j];
						mini= name[j];
					}

		        }
		        avg= sum/array.length ;
		        for (int j=0 ; j<array.length ; j++)
		        {
		        	switch (array[j]/10)
					{
					case 100:
					case 9 :
						exellent += "\n"+ name[j] + "\t" +array[j]+"\n";
						break;
					case 8 :
						veryGgood += "\n" + name[j] + "\t" +array[j] +"\n";	
						break ;		
					case 7 :
						good += "\n" + name[j] + "\t" +array[j] +"\n";	
						break;
					case 6:
					case 5:
						pass += "\n" + name[j] + "\t" +array[j] +"\n";
						break;
						default:
							fail +="\n" + name[j] + "\t" +array[j] +"\n";
						break;
					}
				
		        	if(array[j]>avg)
		        	{
		        		upAvg += name[j] +"\t"+ array[j]+"\n";	
		        	}
		        	else if (array[j]<avg)
		        	{
		        		dwnAvg += name[j] +"\t"+ array[j]+"\n";	
		        		
		        	}
		        
		        }
		        
		        System.out.println(" result = :");
				System.out.println(exellent +"\n"+ veryGgood +"\n"+ good +"\n"+ pass +"\n"+fail);
				System.out.println("Maximum Grade = "+ max +"\t" +maxi);
				System.out.println("Minimum Grade = "+ min +"\t"+mini);
		        
		        System.out.println("average =" +avg);
		    
				System.out.println("ubove average\n"+upAvg +"\n");
				System.out.println("under average\n"+dwnAvg+"\n");
				
	}

}
This article has been dead for over six months. Start a new discussion instead.