Question
Given an integer,n, perform the following
conditional operations,
If n is odd, print Good
If n is even and in the inclusive range of
2 to 5, print Not Good
If n is even and in the inclusive range of
6 to 20, print Good
Program
package ifelse;
import java.util.Scanner;
public class IfElse
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int N = in.nextInt();
if(N%2==1)
{
System.out.println("Good");
}
else
{
if(N >= 2 && N <= 5)
System.out.println("Not Good");
else if(N >= 6 && N <= 20)
System.out.println("Good");
else if(N > 20)
System.out.println("Not Good");
}
}
}
import java.util.Scanner;
public class IfElse
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int N = in.nextInt();
if(N%2==1)
{
System.out.println("Good");
}
else
{
if(N >= 2 && N <= 5)
System.out.println("Not Good");
else if(N >= 6 && N <= 20)
System.out.println("Good");
else if(N > 20)
System.out.println("Not Good");
}
}
}
No comments:
Post a Comment