Wednesday, August 4, 2010

Sample Program using while statement

this program will ask the user to input how many grades you want to compute
and get the average and check if Passed or Failed.

import java.util.Scanner;

public class Grades
{
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
int num;
int grd;
int start=1;
int sum=0;
int ave=0;

System.out.print("How many Grades you want to compute:");
num=input.nextInt();

while(start<=num) { System.out.print("Grade" + start + ":"); grd=inout.nextInt(); sum=sum+grd; ave=sum/num; } System.out.print("The average is:" + ave); if(ave>=75)
{
System.out.println("Remarks: Passed");
}
else
{
System.out.print("Remarks: Failed");
}

}
}

No comments:

Post a Comment