-2

I am new to learning java and have come across an error when trying to print two arguments with println(). I'm not sure I am using the correct terminology here so please correct me if not. The code I am trying to run is.

 System.out.println("Hello","world");

It brings back the error "java: no suitable method found for println(java.lang.String,java.lang.String)"

  • `System.out.println("Hello"+"world");` – John Joe Oct 02 '20 at 12:50
  • 3
    [javadoc](https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#println-java.lang.Object-) is your friend. Method `println()` takes a single argument. – Abra Oct 02 '20 at 12:52
  • https://stackoverflow.com/questions/23772436/system-out-println-and-string-arguments – Marvin Oct 02 '20 at 12:53
  • 3
    Does this answer your question? [System.out.println and String arguments](https://stackoverflow.com/questions/23772436/system-out-println-and-string-arguments) – Marvin Oct 02 '20 at 12:53

3 Answers3

0
void println(String x)

So you can't use it with two arguments. You should do it like this:

System.out.println("Hello");
System.out.println("world");

As result you have following in console:

Hello
world

In case you want to print it in one line, you have various options:

System.out.println("Hello world");
//
System.out.print("Hello ");
System.out.println("world");
//
System.out.print("Hello" + " " + "world");

As result you have following in console:

Hello world
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35
0

It won't print two arguments because, as the error message said, there is no method that accepts two strings as arguments.

You can call the method twice to print two things, or with strings specifically, you can concatenate the arguments.

System.out.print("Hello "); //print instead of println so no line break
System.out.print("World"); //print instead of println so no line break

Or concatenate:

System.out.println("Hello" + " World");
Strikegently
  • 2,251
  • 20
  • 23
0

The method println does not take 2 string in it's parameter. May be you are trying to concatenate the strings like below?

System.out.println("Hello " + "world");
avi
  • 371
  • 1
  • 7
  • 20