0
package takingUserInput;
import java.util.Scanner;

public class ScannerUserInput {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    @SuppressWarnings("unused")
    Scanner sc=new Scanner(System.in);
    String hello=sc.nextLine();
    System.out.println(hello);
    int x=sc.nextInt();
    System.out.println(x);
    double y=sc.nextDouble();
    System.out.println(y);
   //(int/char/float/etc) y=sc.nextInt/Car/Foat/etc)();  
    }

}

Runnig above program gives me output for all three i.e firtstly for string i get to print a line ,secondly i get to print integer and then i get to print a floating number but

package takingUserInput;
import java.util.Scanner;

public class ScannerUserInput {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    @SuppressWarnings("unused")
    Scanner sc=new Scanner(System.in);

    int x=sc.nextInt();
    System.out.println(x);
    double y=sc.nextDouble();
    System.out.println(y);
   //(int/char/float/etc) y=sc.nextInt/Car/Foat/etc)();  
    String hello=sc.nextLine();
    System.out.println(hello);
    }
}

in this program i am not able to run the string after int and the float

0 Answers0