User Tools

Site Tools


java:control_structures:else
click
to support this page (eg 0,42 € or so) Thanks.

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

java:control_structures:else [2013/04/09 11:07] (current)
88.74.72.132 created
Line 1: Line 1:
 +====== else ======
 +<code java>
 + if ( condition == true ){
 +    command;    
 + } else {
 +      // if the "if" condition false
 +      command;
 +      }
 +</code>
 +check if a condition is true or false
  
 +===== example of else=====
 +<code java>
 +
 +
 +package plausibilitycheck;
 +
 +import java.util.Scanner;
 +
 +public class Plausibilitycheck{
 +
 +    /**
 +     * @param args the command line arguments
 +     */
 +    public static void main(String[] args) {
 +
 +        int celsius;
 +        double fahrenheit;
 +
 +        Scanner scan = new Scanner(System.in);
 +
 +        System.out.print("Please type in Celsius : ");
 +        celsius = scan.nextInt();
 +
 +        if (celsius > 0) {
 +
 +            fahrenheit = celsius * 1.8 + 32;
 +            System.out.println(celsius + "° Celsius are " + fahrenheit + "° Fahrenheit");
 +        } else {
 +
 +            System.out.println("invalid Celsius Value ");
 +        }
 +
 +    }
 +}
 +
 +</code>
 +
 +=== output else ===
 +     Please type in Celsius: 0
 +     invalid Celsius Value
 +    
advertising
java/control_structures/else.txt · Last modified: 2013/04/09 11:07 by 88.74.72.132

Impressum