In: Computer Science
Java Programming
Compound Logic and nested if statement
For a student to be accepted in XYZ College, the student must meet the following requirements:
XYZ college asked you to write a program to implement the above requirements.
Submit:
Code (compound logic)
import java.util.*;
public class xyz {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter GPA : ");
double gpa = in.nextDouble();
System.out.println("Enter family income : ");
int i = in.nextInt();
System.out.println("Is New Jersey resident (y/n): ");
char ch = in.next().charAt(0);
if(gpa>=3.75 && i>60000 && ch=='y')
{
System.out.println("Accepted.");
}
else
{
System.out.println("Rejected.");
}
}
}
Code (Nested if)
import java.util.*;
public class xyz {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter GPA : ");
double gpa = in.nextDouble();
System.out.println("Enter family income : ");
int i = in.nextInt();
System.out.println("Is New Jersey resident (y/n): ");
char ch = in.next().charAt(0);
if(gpa<=3.75)
{
System.out.println("Rejected.");
}
else if(i<=6000)
{
System.out.println("Rejected.");
}
else if(ch=='n')
{
System.out.println("Rejected.");
}
else
{
System.out.println("Accepted.");
}
}
}
Terminal Work (code 1)
Terminal Work(code 2)
.