Ask coding questions

← Back to all posts
printf not printing more than one variable
MarcusClark3

When I try to run the following code in java:

class Main{
public static void main (String[] args) {

String myName = "Mr. Clark";
myName = "marcus";

}

the screen does not print past "Hi, my name is " but does not throw an error either. What is going on in Java here?

Voters
MarcusClark3
Comments
hotnewtop
Bunnytoes

you need to write System.out.println("Hi, my name is " + myName + " what?");

ShluffyMonster

Hey, I think the problem is it needs to be entered like this: "Hi, my name is " + myName + " what?". As for what is going on here, so far as I know you need to use + and "" like in js.