0

I try to run this code but it's doesn't work.

package try1;
import java.util.*; // la package qui importe la class scanner 
public class try {
    public static void main(String[] args) {
        Scanner a=new Scanner (System.in);
        System.out.println("tint :");
        int b=a.nextInt();
        System.out.println("double:");
        double c=a.nextDouble();
        System.out.println("char:");
        char d=a.nextLine().charAt(0);
        System.out.println("string:");
        String e=a.nextLine();

        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
    }

}

I'm getting this exception:

Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
    at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
    at java.base/java.lang.String.charAt(String.java:712)
    at ex1.ex1.main(ex1.java:12)
Federico klez Culloca
  • 22,898
  • 15
  • 55
  • 90

0 Answers0