+ 1
Can anyone please help me with the usage of Scanner ,next line and others?
Actually the format given seems to be very different from what I have learnt till now. I request you all to help me to crack this topic and understand it more correctly.
4 ответов
+ 1
To take input, you first need a Scanner object. To make one, simply... make one like the following:
Scanner sc = new Scanner(System.in);
Now, with this object, you can take different types of input. You can take ints, doubles, Strings, chars, and more. To take an int and store in an a variable called "input," do this:
int input = sc.nextInt();
For other types, like double and String, use nextDouble() and nextLine(), respectively. Make sure to change the type of the "input" variable to double and String as well.
If you have any more questions, please ask.
+ 1
thanks buddy
+ 1
@Sheetal
looks fine
0
can anyone tell me what's wrong in this code?
import java.util.Scanner;
class MyClass {
public static void main(String[ ] args) {
Scanner myVar = new Scanner(System.in);
System.out.println(myVar.nextLine());
}
}