!(true)&&(false) equals false.
true
Calculate 89 OR 42 after converting to binary and performing the operation.
BONUS: Create a program that checks if a year is a leap year or not.
Here is how the method should work:
(1) Prompt the user to input any year that they would like
(2) Determine if the year is a leap year or not
(3) Print the necessary dialogue (ex. [year] is/is not a leap year) AND return the value of any boolean(s) used
public class PhysicsStudent implements Comparable<PhysicsStudent> {
private String name;
private double physicsGrade;
public PhysicsStudent(String name, double physicsGrade) {
this.name = name;
this.physicsGrade = physicsGrade;
}
// Getters
public String getName() {
return name;
}
public double getPhysicsGrade() {
return physicsGrade;
}
// Override the compareTo
public int compareTo(PhysicsStudent other) {
if (this.physicsGrade < other.physicsGrade) {
return -1;
} else if (this.physicsGrade > other.physicsGrade) {
return 1;
} else {
return 0;
}
}
}
public class Main {
public static void main(String[] args) {
PhysicsStudent fred = new PhysicsStudent("Fred", 3.8);
PhysicsStudent bob = new PhysicsStudent("Bob", 3.6);
int result = fred.compareTo(bob);
if (result < 0) {
System.out.println("Fred has a lower physics grade than Bob");
} else if (result > 0) {
System.out.println("Fred has a higher physics grade than Bob");
} else {
System.out.println("Fred and Bob have the same physics grade");
}
}
}
Main.main(null);
import java.util.Scanner;
public class EvenOddChecker {
public static boolean isEven(int number) {
return number % 2 == 0;
}
public static void main(String[] args) {
// input
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = sc.nextInt();
boolean result = isEven(number);
if (result) {
System.out.println(number + " is an even number.");
} else {
System.out.println(number + " is an odd number.");
}
sc.close();
}
}