0

I don't want to break the line so I used System.out.print(">>"); but I can't put int (int number = scan.nextInt(); ) inside it and I can't also make System.out.print("<<"); in the same line as the int.

I would like it to run like this: >> 123 <<

    System.out.println(" Enter Number ");
    System.out.print(" >  ");  
    int number = sc.nextInt();
    System.out.print("  < ");

    // like this  > 123 < 
kryger
  • 12,906
  • 8
  • 44
  • 65
  • 3
    how about doing *System.out.println("> "+number+" <");* – SpringLearner Nov 28 '17 at 09:11
  • Or `System.out.format(">%d<%n", number)` – AxelH Nov 28 '17 at 09:15
  • 1
    Ok, reading again, I feel I did answer the wrong problem... you want the user input for the console (here `123`) to not add a new line ? So that you can add a `print(" < ")` on the same line ? Can you confirm please ? – AxelH Nov 28 '17 at 09:22
  • I think you are misunderstanding what OP wants. I think he wants to give the option to user to put the number between '>' and '<', e.g. `Enter Number: > (Insert number here through Scanner) <` – LuisFerrolho Nov 28 '17 at 09:27
  • If my previous comment is answer positivly, then you should check the comment on [How to prevent the enter from making a new line in console after input?](https://stackoverflow.com/questions/41668031/how-to-prevent-the-enter-from-making-a-new-line-in-console-after-input). This is not out-of the box possible. FYI @LuisFerrolho, this is what I said in my comment several minute before you, I did notice my misunderstanding. – AxelH Nov 28 '17 at 09:33
  • @Genevieve - can you clarify the situation based on the comments above please? – achAmháin Nov 28 '17 at 13:29
  • @notyou i wanted to put '>' , numbers and '<' on the same line but it's always like this : > 123 – Genevieve Nov 28 '17 at 14:48
  • I provided an answer below which will output the brackets and user input on the one line. If there is something wrong with it, let me know. – achAmháin Nov 28 '17 at 14:49

1 Answers1

0

You should get the user input before any of the printing, and then just concatenate the result with the >s.

System.out.println(" Enter Number ");
int number = sc.nextInt();
System.out.print(" >  " + number + "  < ");
achAmháin
  • 4,176
  • 4
  • 17
  • 40