Showing posts with label Average. Show all posts
Showing posts with label Average. Show all posts

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");
}

}
}

Thursday, July 8, 2010

IF ELSE statement sample program

This program will compute the 3 grades and get the average. the program will show a message "Your Passed" if the average is 75 above. else the program will show a message " Your Failed" if the average is Below 75.

here is the program.

import java.io.*;

public class ComputeAverage
{
public static void main(String args[])
{
//declaration of variables
int math=90;
int PE=90;
int prog=95;
int ave=0;

//Compute the average

ave=(math + PE + prog)/3;

//display the average
System.out.print("Your average is:" + ave);


//checking the average if it is 75 above or below 75 using if statement

if(ave>=75)
{
System.out.print("Your Passed");
}
else
{
System.out.print("Your Failed");
}

}
}