hpilo

chapter2_SyntaxA_Ex1

Dec 15th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /*      ================================================
  4.         Chapter 2: Syntax section A- conditional clause
  5.  
  6.                     Ex1: Under age or Adult
  7.         ================================================
  8. */
  9.  
  10.  
  11. public class MyProgram {
  12.     public static void main(String[] args) {
  13.  
  14.         //variables
  15.         float age;      //allow the user to enter more precise age in a float number
  16.         Scanner s=new Scanner(System.in);
  17.  
  18.         //user input
  19.         System.out.println("Enter your age: ");
  20.         age=s.nextFloat();
  21.  
  22.         //display message
  23.         if(age<18)
  24.             System.out.println("you are Under age!");
  25.         else
  26.             System.out.println("you are an Adult!");
  27.  
  28.  
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment