answersLogoWhite

0


Best Answer

The method Scanner.nextInt() returns an integer obtained as user input.

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Which scanner class method would you use to read integer as input?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How do you use the Scanner class to store two words or more in a String variable then the next input in another String variable in java?

Scanner scan = new Scanner("[input method]"); // input method could they key board //(System.in) or a String String one = scan.next() + scan.next(); // get the first 2 words and concatenate String two = scan.next(); // the remaining word


How do you accept an integer or a float or double value as a console input from user in java also you do not want to use command line arguments?

Scanner scan = new Scanner(System.in); // A scanner object that reads from the // keyboard( System.in), must import //Scanner class to use this System.out.print("Input Integer: "); int first = scan.nextInt(); //Reads the next int after the printed stuff that the user //inputs System.out.print("Input Double: "); double first = scan.nextDouble(); //Reads the next double after the printed stuff that //the user inputs


How you can restrict the user to input only digits or integers?

import java.util.*;public class tryint{public static void main(String[] args){Scanner s=new Scanner(System.in);int w;try{System.out.print("Input number:");w=s.nextInt();System.out.print("Input number is "+w);}catch(Exception wi){System.out.println("not an integer");}}}


Java program to give input of a string and display it?

import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }


How do you How do you write the special number program in java?

// Addition program that displays the sum of two numbers.import java.util.Scanner; // program uses class Scannerpublic class Addition{// main method begins execution of Java applicationpublic static void main( String args[] ){// create Scanner to obtain input from command windowScanner input = new Scanner( System.in );int number1; // first number to addint number2; // second number to addint sum; // sum of number1 and number2System.out.print( "Enter first integer: " ); // promptnumber1 = input.nextInt(); // read first number from userSystem.out.print( "Enter second integer: " ); // promptnumber2 = input.nextInt(); // read second number from usersum = number1 + number2; // add numbersSystem.out.printf( "Sum is %d\n", sum ); // display sum} // end method main} // end class Addition

Related questions

How would i write a program that takes an integer as an input and reverses its digits as an output?

In java you can do it like this: import java.util.Scanner; public class Sample { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Input an integer: "); int i = input.nextInt(); System.out.print("reverse:"); while(i != 0) { System.out.print(i % 10); i = i / 10; } } }


How do you use the Scanner class to store two words or more in a String variable then the next input in another String variable in java?

Scanner scan = new Scanner("[input method]"); // input method could they key board //(System.in) or a String String one = scan.next() + scan.next(); // get the first 2 words and concatenate String two = scan.next(); // the remaining word


How do you accept an integer or a float or double value as a console input from user in java also you do not want to use command line arguments?

Scanner scan = new Scanner(System.in); // A scanner object that reads from the // keyboard( System.in), must import //Scanner class to use this System.out.print("Input Integer: "); int first = scan.nextInt(); //Reads the next int after the printed stuff that the user //inputs System.out.print("Input Double: "); double first = scan.nextDouble(); //Reads the next double after the printed stuff that //the user inputs


Why does Java accept any input as string by default?

Java doesn't always accept any input as a string it only do that when the input is entered from the " JOptionPane.InputDialog" but it can accept any other data type like integer or short from the console though Scanner class .


How you can restrict the user to input only digits or integers?

import java.util.*;public class tryint{public static void main(String[] args){Scanner s=new Scanner(System.in);int w;try{System.out.print("Input number:");w=s.nextInt();System.out.print("Input number is "+w);}catch(Exception wi){System.out.println("not an integer");}}}


What is the best method of data input for long documents?

scanner,OSR (optical character recognition


How would you write java script code that will prompt a user to enter a number between 1 and 10 and give an error message if its not and continue to prompt them until the proper value is received?

For this, I'll just go ahead and write a sample program: (assume all necessary imports are present) public class prompter{ public static void main(String[] args){ Scanner kb = new Scanner (System.in); int inputValue = 0; System.out.println("Enter a value between 1 and 10:"); String input = kb.nextLine(); try{ inputValue = Integer.parseInt(input); } catch( Exception e) {} while( inputValue < 1 inputValue > 10 ){ System.out.println("Invalid value.\nPlease enter a value between 1 and 10:"); input = kb.nextLine(); inputValue = Integer.parseInt(input); } /* enter whatever code you want here - inputValue will contain an inputted integer between 1 and 10*/ } } This sample program uses Scanner objects to detect user input, and uses the Integer class's parseInt() method to interpret that input, using a try/catch statement to first make sure that the input is in fact an integer.


Is a scanner a input device?

Yes, a scanner is AN input device.


Scanner is output or input device?

scanner is an input device. it is used to store data in a computer.


Is a scanner is a input or an output?

A scanner is an input device, like a microphone. You cannot send data from your computer to the scanner, only from the scanner to the computer.


Java program to give input of a string and display it?

import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a string:"); String input = in.next(); System.out.println("The String you entered is: " + input); } }


Is an scanner an input or output device?

A scanner is an input device because it sends (or 'inputs') information to the computer.