0

can any one please explain me the input function clearly?

i just dont get how do i implement it in a simple program whether i want to get input

6th Dec 2016, 1:48 PM
Impeccable Hasib
Impeccable Hasib - avatar
5 Respostas
+ 1
According to my view Combining System.in and java.util.Scanner provides a best way to read user input that can run inside an IDE. It also provides a way to read different data types.  For reading string input:  import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("What is your favorite color? "); String name = scanner.next(); System.out.println("Your favorite color is: " + name); } } Now you can use for different types of input like For reading Byte : byte number = scanner.nextByte(); Integer : int number = scanner.nextInt(); Double : double number = scanner.nextDouble(); Boolean : boolean bool = scanner.nextBoolean(); Short : short number = scanner.nextShort(); Long : long number = scanner.nextLong(); Float : float number = scanner.nextFloat(); There are also different ways to read input from user like BufferedReader and InputStreamReader
6th Dec 2016, 2:07 PM
Vipul Walia
Vipul Walia - avatar
+ 1
Yes i guess it's much more easier to implement.
6th Dec 2016, 2:12 PM
Vipul Walia
Vipul Walia - avatar
0
so compared to other scanner is the easiest way to get input?
6th Dec 2016, 2:11 PM
Impeccable Hasib
Impeccable Hasib - avatar
0
thanks a lot :)
6th Dec 2016, 2:14 PM
Impeccable Hasib
Impeccable Hasib - avatar
0
first import java.util.Scanner; on the tip of the class secondly create the object inside main or in declaration area in ur class: Scanner in = new Scanner(System.in); now if ur input variable is already declared do this. if ur input is integer: int a = in.nextInt(); if ur input is string or char: char a = in.nextLine(); String a = in.nextLine();
7th Dec 2016, 11:46 AM
Shaima