Java Scanner Reading an input line

14.4k Views Asked by At

I was wondering how can I make a scanner in java that will read a line that you input. For example:

package first.test;
import java.util.Scanner;

public class FirstTest {

    public static void main(String[] args) {        
        Scanner input = new Scanner(System.in);
        int binaryout;

        System.out.println("This converts base 10 numbers to binary numbers.");
        System.out.println("Please enter your Base 10 Number:");
        //I WANT THE INPUT TO GO HERE!!!!!!!!

       }
}

Any help would be great!

EDIT: Well, looking back at this question, the answer is blatantly obvious, do a google search. yes i did, but the problem is that i was such a noob, i couldnt modify or apply ideas to my projects. sorry for the inconvenience. if there are any ideas on how to edit the question to make it relevant, that would be great. because its just so bad, i dont know how.

1

There are 1 best solutions below

8
user1084563 On BEST ANSWER

I believe you're looking for input.nextLine();? Or if you know it's base 10 then input.nextInt() or if it's longer input.nextLong(). In the future your best starting place is the java documentation especially since you already knew the class that you were trying to make use of. If you look at the docs for Scanner (and maybe search the page for 'line') you'll find what you were looking for:

https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#nextLine()