Java Java Basics Getting Started with Java Strings and Variables

I am not seeing my name change from Craig, even though I am typing it as console.printf("%s is learning Java\n", first);

I am not seeing my name change from Craig, even though I am typing it as console.printf("%s is learning Java\n", firstName); it is still showing the old string using the old name even though I clear it and run javac Introductions.java java Introductions... is it an error on my end or the system? Ive closed and opened console and saved the changes but the code still says (Craig

2 Answers

Steven Parker
Steven Parker
170,303 Points

The name that will be shown is determined by the line that assigns "firstName", which is done before the line containing the "printf".

It looks like you forgot to assign the variable to the string on the line before this one.

An example of this would be something like: String firstName = "Brad";

The data type is String (the first thing listed in the code above) and the variable name you're assigning is firstName. What you follow it with, with the = afterward is the name you want it to assign to that variable surrounded by quotes.

Hope this helps! :)