User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







java:control_structures:else

else

 if ( condition == true ){
    command;    
 } else {
      // if the "if" condition false
      command;
      }

check if a condition is true or false

example of else

 
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 ");
        }
 
    }
}

output else

   Please type in Celsius: 0
   invalid Celsius Value
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
java/control_structures/else.txt · Last modified: 2024/02/16 01:03 (external edit)

Impressum Datenschutz