This shows you the differences between two versions of the page.
|
java:control_structures:if [2013/04/09 10:51] 88.74.72.132 created |
java:control_structures:if [2024/02/16 01:03] (current) |
||
|---|---|---|---|
| Line 5: | Line 5: | ||
| } | } | ||
| </code> | </code> | ||
| - | checks if a condition is true or false | + | check if a condition is true or false |
| - | ===== example of if ===== | + | ===== example of if in java ===== |
| <code java> | <code java> | ||
| Line 34: | Line 34: | ||
| fahrenheit = celsius * 1.8 + 32; | fahrenheit = celsius * 1.8 + 32; | ||
| System.out.println(celsius + "° Celsius are " + fahrenheit + "° Fahrenheit"); | System.out.println(celsius + "° Celsius are " + fahrenheit + "° Fahrenheit"); | ||
| - | } else { | + | } |
| - | + | ||
| - | System.out.println("invalid Celsius Value "); | + | |
| - | } | + | |
| } | } | ||
| Line 43: | Line 40: | ||
| </code> | </code> | ||
| + | |||
| + | |||
| + | === a other example === | ||
| + | <code java> | ||
| + | if ( (name == "meier" || name == "müller") && place =="hamburg" ) { | ||
| + | //if the name meier or müller & the place hamburg | ||
| + | } | ||
| + | if (! ( (name == "meier" || name == "müller") && place =="hamburg" ) ) { | ||
| + | //if the name not meier or müller & the place not hamburg | ||
| + | } | ||
| + | </code> | ||
| + | |||
| === output if === | === output if === | ||