Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Exercise 1 - Using Boolean for gender
- -----------------
- import java.util.Scanner;
- public class Ex1 {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- // Declaring variables
- int year, id;
- final int currentYear = 2019;
- float height;
- boolean gender;
- String gen = "";
- // Getting data from the user using the Scanner object
- System.out.print("Please enter your year of birth:");
- year = s.nextInt();
- System.out.print("Please enter your ID number:");
- id = s.nextInt();
- System.out.print("Please enter your height:");
- height = s.nextFloat();
- System.out.print("Please enter true if your gender is male:");
- gender = s.nextBoolean();
- // Printing the result. The user's age is calculated by subtracting the year input from the current year
- System.out.println("Your age is " + (currentYear - year) + ", ID number: " + id +
- ", height: " + height + ", Male?: " + gender + ".");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement