Showing posts with label if else in java. Show all posts
Showing posts with label if else in java. Show all posts

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

}
}

Wednesday, July 7, 2010

If Statement

IF statement - is a conditional statement.

syntax:

if(conndition)
{
statement 1;
}

IF ELSE - also conditional statement that the program will choose the true statement or false statement depending on thier condition.

syntax:
if(condition)
{
statement 1;
stmt 2;
}
else
{
statement 1;
stmt 2;
}