0

here is my simple question:... How can I eliminate the 'nextline' after a scanner output?

System.out.println("Player 1: Rock (1), Paper (2) or Scissors?(3)");

int p1 = input.nextInt();

if (p1 == 1) {
    System.out.print("= rock\n");
} else if (p1 == 2) {
    System.out.print("= paper\n");
} else {
    System.out.print("= scissors\n");
}

outcome:

Player 1: Rock (1), Paper (2) or Scissors?(3)

1

= rock

desired outcome

Player 1: Rock (1), Paper (2) or Scissors?(3)

1 = rock

Thanks to you all

Nowhere Man
  • 19,170
  • 9
  • 17
  • 42
asumic27
  • 1
  • 1

1 Answers1

0

With nextInt() you have to press enter so I don't think you can Maybe look at other ways to get an input such as: System.in.read()

(Java) How to get user input without pressing the "enter" key

Jake Yoon
  • 120
  • 1
  • 5