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"); } } }
5 Answers
+ 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.
0
In first line you have to write
import java.util*;
0
ye,i wrote,my output is not correct because of (equals) i think
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