Please look at this code for me. Why won\'t the error message display when \"0\"
ID: 3527705 • Letter: P
Question
Please look at this code for me. Why won't the error message display when "0" is entered for the rate? I am sure I did something wrong that was simple. Need back in a hurry. Thanks in advance. r/ import java.util.Scanner; class interest10 { private static Scanner scan; public static void main(String[] args) { scan = new Scanner(System.in); double Ret; System.out.println("Initial Investment:"); int Inv = scan.nextInt(); System.out.println("Duration in years:"); int Year = scan.nextInt(); System.out.println("interest rate?:"); int Rate = scan.nextInt(); if(Inv==0 || Year ==0) { System.out.println("Error in Input...Exiting"); System.exit(0); if (rate==0 || Year ==0) System.out.println("z1ero interest looser...Exiting"); System.exit(0); } Ret = Inv + (Inv*Rate*Year)/100; System.out.println("Tottal Amount: " + Ret ); } }Explanation / Answer
import java.util.Scanner; class interest10 { private static Scanner scan; public static void main(String[] args) { scan = new Scanner(System.in); double Ret; System.out.println("Initial Investment:"); int Inv = scan.nextInt(); System.out.println("Duration in years:"); int Year = scan.nextInt(); System.out.println("interest rate?:"); int Rate = scan.nextInt(); if(Inv==0 || Year ==0) { System.out.println("Error in Input...Exiting"); if (Rate==0 || Year ==0) System.out.println("z1ero interest looser...Exiting"); System.exit(0); } Ret = Inv + (Inv*Rate*Year)/100; System.out.println("Tottal Amount: " + Ret ); } } you kept rate in lower case whereas u declared it as Upper case Rate