Assuming the given values are "Alice", and 165.
"Alice, you are tall enough to go on this ride!"
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your height in cm: ");
int height = scanner.nextInt();
if (height > 150) {
System.out.println(name + ", you are tall enough to go on this ride!");
} else {
System.out.println(name + ", you are not tall enough to go on this ride");
}
}
}
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the width of the rectangle: ");
int width = scanner.nextInt();
System.out.print("Enter the length of the rectangle: ");
int length = scanner.nextInt();
if (length == width) {
System.out.println("The shape is a square");
}
else {
System.out.println("The shape is a rectangle");
}
}
}
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = scanner.nextInt();
if (number % 2 == 0) {
System.out.println("The number " + number + " is even");
}
else {
System.out.println("The number " + number + " is odd");
}
}
}
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your name: ");
String name = scanner.nextLine();
System.out.print("Enter your score (out of 100): ");
int score = scanner.nextInt();
if (score >= 90) {
System.out.println("Excellent work, " + name + ". You have passed with distinction");
}
else if (score >= 50 & score < 90) {
System.out.println("Good job, " + name + ". You have passed");
}
else {
System.out.println("Sorry, " + name + ". You have failed. Please try again");
}
}
}
Close
Assuming the given values are "female" and 70.
"Ma'am, you qualify for a senior citizen discount."
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter your gender (male/female): ");
String gender = scanner.nextLine();
System.out.print("Enter your age: ");
int age = scanner.nextInt();
if (age < 12) {
System.out.println("You qualify for a child discount.");
} else if (age >= 60) {
if (gender.equals("male")) {
System.out.println("Sir, you qualify for a senior citizen discount.");
} else if (gender.equals("female")) {
System.out.println("Ma'am, you qualify for a senior citizen discount.");
} else {
System.out.println("You do not qualify for any discount.");
}
} else {
System.out.println("You do not qualify for any discount.");
}
}
}
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter temperature in Celsius: ");
double celsius = scanner.nextDouble();
double fahrenheit = (9.0/5.0 * celsius) + 32;
if (fahrenheit < 40) {
System.out.println("At " + fahrenheit + "°F, it is considered cold");
}
else if (fahrenheit >= 40 && fahrenheit <= 68) {
System.out.println("At " + fahrenheit + "°F, it is considered warm");
}
else {
System.out.println("At " + fahrenheit + "°F, it is considered hot");
}
}
}
Close
import java.util.Scanner;
public class LeapYearChecker {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = scanner.nextInt();
if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
System.out.println("The year " + year + " is a leap year.");
} else {
System.out.println("The year " + year + " is not a leap year.");
}
} else {
System.out.println("The year " + year + " is a leap year.");
}
} else {
System.out.println("The year " + year + " is not a leap year.");
}
}
}
Close
Assuming the given values are a base salary of $50,000 and 7 years of service.
With a base salary of $50000 and 7 years of service, your final salary is $52500.
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the years of service: ");
int yearsOfService = scanner.nextInt();
System.out.print("Enter the base salary: ");
double baseSalary = scanner.nextDouble();
double finalSalary = baseSalary;
if (yearsOfService >= 10) {
finalSalary = baseSalary * 1.1;
}
else if (yearsOfService >= 5 && yearsOfService <=9) {
finalSalary = baseSalary * 1.05;
}
System.out.println("With a base salary of " + baseSalary + " and " + yearsOfService + " years of service, your final salary is " + finalSalary);
}
}
Close
Assuming the given values are a base price of $50, quantity of 15 items, and the customer is not a member.
The final price for 15 items at a base price of $50 is $600.00.
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Are you a member (yes/no):" );
String membership = scanner.nextLine();
System.out.print("Enter the base price of the item:" );
double basePrice = scanner.nextDouble();
System.out.print("Enter the quantity of items purchased:" );
int quantity = scanner.nextInt();
double finalPrice = basePrice * quantity;
if (membership.equals("yes")) {
if (quantity >= 10) {
finalPrice = finalPrice * 0.7;
}
else {
finalPrice = finalPrice * 0.9;
}
}
else {
if (quantity >= 10) {
finalPrice = finalPrice * 0.8;
}
}
System.out.println("The final price for " + quantity + " of items at a base price of " + basePrice + " is " + finalPrice);
}
}
Close
For a full-time employee with a salary of 1000:
"As a full-time employee, your monthly salary before the bonus is 1000, and after the bonus it is 1150."
Close
import java.util.Scanner;
public class IF_Statements {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String workType = "part-time";
double monthlySalary = 1000;
double salaryBonus = monthlySalary;
if (workType.equals("full-time")) {
salaryBonus = monthlySalary * 1.15;
}
else {
salaryBonus = monthlySalary * 1.10;
}
System.out.println("As as " + workType + " employee, your monthly salary before the bonus is " + monthlySalary + " , and after the bonus it is " + salaryBonus);
}
}
Close