Page 1 of 1

Fehler "StringIndexoutOfboundSexception" Fehler

Posted: 02 Apr 2025, 04:12
by Anonymous

Code: Select all

Code:
char a=sc.next().charAt(0);
char b=sc.nextLine().charAt(0);
System.out.println(a);
System.out.println(b);
Input: "abc"
Output: StringIndexOutOfBoundsException
Ich verstehe nicht, warum es in diesem Fall ein Fehler gibt, aber wenn ich "ABC fgh" eingehe, funktioniert es einwandfrei.