MidtermIISG - Miterm II Study Guide For more Questions:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Miterm II Study Guide For more Questions: ddixit@uwm.edu If statement example: The following program, assigns a grade based on the value of a test score: an A for a score of 90% or above, a B for a score of 80% or above, and so on. class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } } The output from the program is: Grade = C You may have noticed that the value of testscore can satisfy more than one expression in the compound statement: 76 >= 70 and 76 >= 60 . However, once a condition is satisfied, the appropriate statements are executed (grade = 'C';) and the remaining conditions are not evaluated.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Here is a basic example of NESTED if Statements: public class MainClass { public static void main(String[] arg) { int a = 2 ; if (a == 0 ) { System.out.println( "in the block" ); if (a == 2 ) { System.out.println( "a is 0" ); } else { System.out.println( "a is not 2" ); } } else { System.out.println( "a is not 0"
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/22/2010 for the course COMPSCI CS201 taught by Professor Sorenson during the Spring '10 term at Wisconsin Milwaukee.

Page1 / 5

MidtermIISG - Miterm II Study Guide For more Questions:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online