0

Why I’m always getting InputMismatchError in java

import java.io.*; import java.util.*; class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); String s=sc.nextLine(); int t=sc.nextInt(); String result=""; String dir; while(t!=0) { dir=sc.nextLine(); int r=sc.nextInt(); if(dir=="L") result=s.substring(r%s.length(),s.length())+s.substring(0,r%s.length()); //if(dir=='R') System.out.print(result); t--; } } }

4th Aug 2018, 2:56 PM
Bala Krishna
Bala Krishna - avatar
1 Réponse
+ 1
you are not entering your data correctly: string 3 string 2 string 1 string 0 nextLine finishes the line your integer was on.
4th Aug 2018, 7:34 PM
John Wells
John Wells - avatar