Java Scanner | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Java Scanner

Hello I have a question about java scanner... ----------------------------------------------------------------- java.util.Scanner; Is there anyway to not print the value of the user's value and the question after the user entered the value, but stores the value of it? For example _______________________________ Please enter a number: *After I enter the number the output* Please enter a number: 5 ____________________________ Is there anyway not to show the "Please enter a number: 5" but get the data from the users? In other words... How to hide the "Please enter a number: " after user enters the value of it? Thank you - Orange

15th Dec 2019, 3:35 PM
KingDaniel2004
KingDaniel2004 - avatar
6 Answers
+ 5
I mean after the user enters the value, then how to hide the question? LOL IS IT EVEN POSSIBLE to unprint something?🤣 For example : ______________________________ Step 1: Enter a number : Step 2: *Me enters "8"* Step 3: *the question hides away with the data "8". _________________________
15th Dec 2019, 4:17 PM
KingDaniel2004
KingDaniel2004 - avatar
+ 2
Unfortunately, this is not possible in Java while maintaining portability (usability on multiple platforms). See: https://stackoverflow.com/a/15160810
16th Dec 2019, 4:52 AM
LunarCoffee
LunarCoffee - avatar
+ 1
you can use the systems way to clear the console. it will just push it up out of the screen. for windows Runtime.getRuntime().exec("cls"); for mac or Linux Runtime.getRuntime().exec("clear");
15th Dec 2019, 4:23 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
Is your question is : You want to take some no.values but you want ask only ones to ask to enter? Or you want to clear screen after reading? For 1st one, it depends on your code. For 2nd one, its better to use reading password method...
15th Dec 2019, 4:49 PM
Jayakrishna 🇮🇳
+ 1
Why you need it? In C, clrscr() method is available. but does not support all compiler,(i guess). In c++, some compiler support \b back space support for that. In java also, this \b works in some compilers i guess. But all this for user clear understanding purpose.
15th Dec 2019, 4:58 PM
Jayakrishna 🇮🇳
0
for the phrase "Please enter a number :" it is displayed because you print it, Scanner has nothing to do with it. without it how is the user going to know what to do? for the input "5" use readPassword() to treat it like a password readPassword is in java.io.Console.readPassword
15th Dec 2019, 4:05 PM
Bahhaⵣ
Bahhaⵣ - avatar