-4
public void showOver(char x, int v){ System.out.println(x,v); } }

I have try to pass x and v to "Println" like above and I've got an error

why?

  • 3
    Because `PrintStream.println` only accepts a single parameter. Join them together somehow, e.g. add them, or concatenate them into a string. – Andy Turner Feb 24 '17 at 10:05

2 Answers2

3

System.out.println() only takes a single argument. You need to concatenate x and v somehow into a single String.

Multiple solutions, the easiest

System.out.println(x + ", " + v);

others might include

System.out.println(String.format("%c, %d", x, v));

You can also use System.out.printf(), but note this does not include a newline, so you'll need to add

System.out.printf("%c, %d\n", x, v);
Adam
  • 35,919
  • 9
  • 100
  • 137
2

Use printf:

System.out.printf("%c, %d", x, v)
peterremec
  • 488
  • 1
  • 15
  • 46