Blog Detail

September 23, 2023

Java Data Types Exercises – Part 4

  • What is the output of this code?

                    class Main {
      public static void main(String[] args) {
        int numberOfAttendance = 10;
        int seats = 18;
    
        boolean areSeatsEnough = seats >= numberOfAttendance;
    
        System.out.println("Are seats enough? " + areSeatsEnough); 
      }
    }
  • This code checks if a product is in stock. What is the output of this code?

                    class Main {
      public static void main(String[] args) {
        int availableQuantity = 25;
        int requestedQuantity = 15;
        
        boolean isInStock = requestedQuantity <= availableQuantity;
        
        System.out.println("Is the product in stock? " + isInStock); 
      }
    }
  • This code checks age eligibility for a movie. What is the output of it?

                    class Main {
      public static void main(String[] args) {
        int age = 14;
        int minimumAgeRequirement = 16;
        
        boolean isEligible = age >= minimumAgeRequirement;
        
        System.out.println("Is the person eligible to watch the movie? " + isEligible);
      }
    }
  • Define a proper data type for the isWithinBudget variable.

                    class Main {
      public static void main(String[] args) {
        double productPrice = 49.99;
        double budget = 100.00;
        
        "" isWithinBudget = productPrice <= budget;
      }
    }
  • Define a proper data type for the carMileage variable.

                    class Main {
      public static void main(String[] args) {
        "" carMileage = System.console().readLine("Enter your car mileage: ");
      }
    }
  • Java Exercises for Data Types

    • If you've faced difficulties with these exercises, take a look at Data Types Module on my Java course.


    You can also share 'Java Data Types' Exercises on your:
    X (Twitter) - Telegram - Linkedin - Facebook - or on your favorite platform...




    Happy Coding!
    Behnam Khani