public class Admission { public static void main(String[]args){ String strAmount
ID: 3625727 • Letter: P
Question
public class Admission {public static void main(String[]args){
String strAmount1;
String strAmount2;
double amt1;
double amt2;
strAmount1= JOptionPane.showInputDialog(null, "Enter amount1:");
amt1= Double.parseDouble(strAmount1);
strAmount2= JOptionPane.showInputDialog(null, "Enter amount2:");
amt2= Double.parseDouble(strAmount2);
if(amt1 >= 3.0 && amt2 >= 60){
System.out.println("Accepted");
}
else if (amt1 < 3.0 && amt2 >= 80){
System.out.println("Accepted");
}
else{
System.out.println("Rejected");
}
}
}
MYQUESTION IS THAT: should i use both && operator in my if and else if statement or should i use && for the if and || for else if. Kindly help me im confused what to use..tnx
Explanation / Answer
It depends on what you want the program to do. As stated, it will only print "Accepted" if either (a) both amt1 is greater than or equal to 3.0 AND amt2 is greater than or equal to 60 -OR- (b) amt1 is less than 3.0 AND amt2 is greater than or equal to 80. Here's an example of some accepted and rejected values amt1 = 4 , amt2 = 77 => Accepted amt1 = 3 , amt2 = 80 => Accepted amt1 = 2.9 , amt2 = 79.9 => Rejected amt1 = 2.9 , amt2 = 80 => Accepted amt1 = 3 , amt2 = 59 => Rejected I can provide more help if you give the programming objectives. I do not know what criteria your amt1 and amt2 have to meet.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.