package newproj;
import java.util.Scanner;
public class MyFirstClass
{
public static void main(String[] args)
{
char a;
int b;
Scanner sc = new Scanner(System.in);
System.out.print("Enter value b: ");
b= sc.nextInt();
System.out.print("Enter char: ");
a = sc.nextLine().charAt(0);
System.out.println("This is "+a);
}
}
The error reflected on console during runtime is Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: -1.
Can someone teach me how to scan a character after scanning an integer. In C programming, there is the "fflush(stdin)" to help the scanf function. So, I was thinking along the line that the newline character was scanned in instead.