HackerRank Java Questions and Answers
HackerRank Java Questions and Answers
2. Java If-Else
Given an integer, if the number is odd, print 'Weird'. If even and in the inclusive range of 2 to
5, print 'Not Weird'. If even and in the inclusive range of 6 to 20, print 'Weird'. If even and
if (N % 2 != 0) {
System.out.println("Weird");
} else {
if (N >= 2 && N <= 5) {
System.out.println("Not Weird");
} else if (N >= 6 && N <= 20) {
System.out.println("Weird");
} else {
System.out.println("Not Weird");
}
}
}
}
Read an integer, a double, and a String, and print them in reverse order.
import java.util.Scanner;