---
title: "How to use the Scanner class in java?"  
description: "How to use the Scanner class in java?"  
author: "Anonymous User"  
published: 2013-10-04  
updated: 2013-10-04  
canonical: https://www.mindstick.com/forum/1579/how-to-use-the-scanner-class-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to use the Scanner class in java?

I was doubting how, I could read [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) from the [console](https://www.mindstick.com/blog/210/the-console-class) using the [Scanner](https://www.mindstick.com/forum/33502/java-scanner-issue-why-input-is-skipped-when-using-next-nextint-etc-after-nextline) [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp)?

here's some [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
Scanner ob=new Scanner(System.in);System.out.println("Enter your username: ");String username=ob.nextLine();System.out.println("Enter the value of a");int a=ob.nextInt();
```

So basically all I want to do is have the scanner read an input for the [username](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username), and assign the input to a [String](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) variable.

Thanks!

## Replies

### Reply by Anonymous User

```
import java.util.Scanner;public class scanner{    public static void main (String[]args)    {        int number1,int number2, sum;        Scanner input = new Scanner (System.in);        System.out.print("Enter First multiple");        number1 = input.nextInt();        System.out.printlin ("Enter second multiple");        Number2 = input.nextInt();        sum = number1 * number2;        System.out.printf ("The product of both number is %d" , sum);    }}
```


---

Original Source: https://www.mindstick.com/forum/1579/how-to-use-the-scanner-class-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
