import java.util.*;
class DataTypes {
public static void main(String args[]) {
int i = 4;
double d= 4.0;
String s = "Hackerrank";
Scanner scan = new Scanner(System.in);
int j = scan.nextInt();
double d1 = scan.nextDouble();
String s1 = new String();
s1 = scan.nextLine();
j = j+i;
System.out.println(j);
d1 = d1+d;
System.out.println(d1);
System.out.println(s+" "+s1);
scan.close();
}
}
See the above code it is error free but after I input the double the program does not read the string it directly shows the output. But When I comment the scanning statements of int and double then the programs reads my string. Why is it so?
Scannerif your value is already set?Scannerallows you to input values in the console ...it serves you to verify that your result is correct or that a variable has good values. This is not a GUI that you can format... This is more an information.