+ 1

What's wrong with my code đŸ€”đŸ€”

import java.util.*; public class Program { public static void main(String[] args) { char firstname,lastname,gender,email,password; try{ Scanner in=new Scanner(System.in); System.out.println("Enter first name"); firstname=in.nextChar(); System.out.println("Enter last name"); lastname=in.nextChar(); System.out.println("Enter your gender M/F"); gender=in.nextChar(); System.out.println("Enter your email address"); email=in.nextChar(); System.out.println("Enter new password"); password=in.nextChar(); //Displaying output System.out.println("Welcome to facebook "+firstname+" "+lastname); } catch (Exception e) { } } } https://code.sololearn.com/csQyMxi6zs3D/?ref=app

8th Oct 2018, 6:56 AM
Amal P Mathew
Amal P Mathew - avatar
3 Answers
+ 3
Use String instead of char; and BTW Scanner class doesn't have nextChar() method, that's the majority of the problems with the code. String firstname, lastname, gender, email, password; firstname = in.nextLine(); lastname = in.nextLine(); Do the same for gender, email and password. Hth, cmiiw
8th Oct 2018, 7:38 AM
Ipang
+ 3
Ipang Thanks brother it works 😊
8th Oct 2018, 7:59 AM
Amal P Mathew
Amal P Mathew - avatar
+ 3
You're welcome bro, glad if it helps : )
8th Oct 2018, 8:00 AM
Ipang