Question:-
You have an answering protocol when your mobile rings.
1. You never answer it when you are sleeping.
2. You answer it in the morning, only if your mother calls.
3. All other times you answer it.
Write a Java program to decide whether you must answer the phone call or not.
Input specification:
3 Boolean variables - isMom, isAsleep, isMorning
Output specification:
true if you answer, false if you do not answer.
Sample input:
false
false
false
Sample output:
true
Source Code:-
import java.util.*;
class CallAns{
public static void main(String []args){
Scanner s=new Scanner(System.in);
boolean isMom=s.nextBoolean(),isAsleep=s.nextBoolean(),isMorning=s.nextBoolean();
System.out.println(isAsleep?false:(isMorning?isMom:true));
}
}
No comments:
Post a Comment