A program can test multiple cases by placing if…else statements inside other if…else
statements to create nested if…else statements. For example, the following pseudocode
represents a nested if…else
If student’s grade is greater than or equal to 90
Print “A”
else
If student’s grade is greater than or equal to 80
Print “B”
else
If student’s grade is greater than or equal to 70
Print “C”
else
If student’s grade is greater than or equal to 60
Print “D”
else
Print “F” This pseudocode may be written in Java as
public class Apples {
public static void main(String[] args){
int studentGrade = 91;
if ( studentGrade > 90 )
System.out.println( "he got an A" );
else if (studentGrade > 80 )
System.out.println(" he got B ");
else if (studentGrade > 75 )
System.out.println(" he got C ");
else if (studentGrade > 60 )
System.out.println(" he got D ");
else
System.out.println( "Failed" );
}
}
Good class but I have a suggestion ... on the colored words could you use a lighter color as it is hard to identify the words on the darker colors . Thank you !!!
ReplyDelete