I have this program to reverse the order of words, but the input is messed up. This is my output log.
1
this is a trial
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Store_Credit.main(Store_Credit.java:13)
Process finished with exit code 1
And, here is my code :
import java.util.Scanner;
public class Reverse_Words {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N;
N = scanner.nextInt();
for(int i = 0; i < N; i++) {
int h = i+1;
String[] s = scanner.nextLine().split(" ");
System.out.print("Case #"+h+": ");
for(int j = s.length-1; j >=0; j++) {
System.out.print(s[j]+" ");
}
System.out.println();
}
}
}