Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMd. Jafrin Hossain
6,577 PointsStucking here
String firstName = console.readLine ("First name? "); String lastName = console.readLine (" last name? "); console.printf("First name: %s", firstName); console.printf("Last name: %s", lastName);
3 Answers
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsHello Md. Jafrin Hossain
I checked the code that you provided above and it works just fine when I tested every line.
Anyway here is my code which is similar to yours.
String firstName =console.readLine ("what is your first name?");
String lastName =console.readLine ("what is your first name?");
console.printf("First name: %s", firstName);
console.printf("Last name: %s", lastName);
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsInstead of working with console object please replace it with Scanner Object for Eclipse IDE. You will also need to import the Scanner Object using this line _ import java.util.Scanner; _
// Console console = System.console(); remove the Console Object and replace it with Scanner
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name");
String name = scanner. nextLine();
System.out.println("Enter an adjective");
String adjective = scanner. nextLine();
System.out.printf("%s is very %s", name, adjective);
Please let me know if this helps
Md. Jafrin Hossain
6,577 PointsThank you so much for your help brother.
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 PointsMd. Jafrin Hossain glad it worked, the only disadvantage of the Scanner Object is you have to prompt the user manually using System.out.println() method.
Md. Jafrin Hossain
6,577 PointsYes, I have got it.
Md. Jafrin Hossain
6,577 PointsMd. Jafrin Hossain
6,577 PointsThank you so much for the reply Tonnie Fanadez . Would you kindly help me in the following section
Code in my ide(eclipse):
package treehouse; import java.io.*;
public class Chechk { public static void main(String[] args) { String fn = "Jafrin"; System.out.println(fn);
}
output: Exception in thread "main" java.lang.NullPointerException at treehouse.Chechk.main(Chechk.java:10) Jafrin
Why it shows NullPointerException?