java.util.scanner - how to take input in Java from user? -
i new java quite @ c. want take input user in java. please suggest basic concept exact code? thanks
import java.util.scanner; public class main { public static void main (string [] args) { scanner sc = new scanner(system.in); string inputtext = sc.nextline(); } } import java.util.scanner;
imports java library allow read data specified input source.
scanner sc = new scanner(system.in); gets working instance of scanner library in sc go input standard input of system, system.in, in our case, keyboard.
string inputtext = sc.nextline(); this code asks sc instance line of text typed user , set inputtext variable.
note when sc.nextline() called, halts execution , waits user input , proceeds when user presses enter on keyboard.
Comments
Post a Comment