I'm trying to debug an error of my code (I'm still very new to Java) for an assignment.
public static void main(String[] args) throws Exception {
System.out.println("Hi, Welcome!");
Scanner inpt = new Scanner(System.in);
System.out.print("What can I call u? : ");
String user = inpt.nextLine();
Pelanggan user = new Pelanggan();
}
"Pelanggan" is the name of the class that I made. I want to assign the value of user into the class Pelanggan but I got this error
Duplicate local variable user
Then I tried to change the code into this
public static void main(String[] args) throws Exception {
System.out.println("Hi, Welcome!");
Scanner inpt = new Scanner(System.in);
System.out.print("What can I call u? : ");
Pelanggan user = inpt.nextLine();
user = new Pelanggan();
}
Then I got this error
Type mismatch: cannot convert from String to Pelanggan
I have tried to look for the solution but still haven't found a solution which is worked out on my code.
How can I fix this?
Any help would be greatly appreciated! Thank you