0

Java.Whats wrong with my code? Help pls

You task is to write Java program, which check user id and password. If user id and password match with already existed information, you need to return the balance of the account. public class Assignment1 { public static void main (String [] args){ Scanner sc=new Scanner (System.in); System.out.println("Welcome to the bank. Please, enter the user id:"); int id=sc.nextInt(); System.out.println("Please, enter the password:"); String [] password = {"One","Two","Three","Four","Five"}; String ent_pass = sc.next(); if(ent_pass.equals(id-1)){ String [] balance = {"90.67", "87.5", "1200", "32", "54"}; System.out.println(balance[id-1]); } else { System.out.println("the password doesn’t match"); } } }

19th Jan 2021, 2:24 PM
Ruslan
5 Antworten
+ 2
First, please make a Java code and paste your program in that code, then save it and link it here. This way it will be easier to reference line numbers and compiler errors. For now, I will be referencing line numbers from the first line. So first of all, as Atul said, you need to import java.util.* to access the Scanner class. Then, on line 9, `if (ent_pass.equals(id - 1))` here `ent_pass` is a String and `id` is an int. Passing int to String.equals method will always return false.
19th Jan 2021, 2:45 PM
XXX
XXX - avatar
0
In first line you have to write import java.util*;
19th Jan 2021, 2:36 PM
Atul [Inactive]
0
ye,i wrote,my output is not correct because of (equals) i think
19th Jan 2021, 2:40 PM
Ruslan
0
Welcome to the bank. Please, enter the user id: 1 Please, enter the password: One the password doesn’t match. Here it should match and shows balance
19th Jan 2021, 2:41 PM
Ruslan