User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







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

if

 if ( condition == true ){
    command;    
 }

check if a condition is true or false

example of if in 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");
        } 
 
    }
}

a other example

        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
        }

output if

   Please type in Celsius: 5
   5° Celsius are 41.0° Fahrenheit
  
advertising
java/control_structures/if.txt · Last modified: 2013/04/10 10:35 by 94.223.12.247

Impressum