The program is supposed to take a sentence inputted by the user such as "I am very hungry" and then ask a number of words to rotate. If the number was 2 the new output would be "very hungry I am". This is my code so far but I seem to have an error. When I run the code, this appears: java.util.InputMismatchException. There is also some other information that appears under it but I am not sure what it means. This is my code so far.
import java.util.*;
public class WordRotation
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.println("Enter a sentence");
if(input.hasNext());
{
String s = input.next();
String[] words = s.split(" ");
System.out.println("Enter number of words to be rotated");
int rotation = input.nextInt();
for (int i = 0;i < words.length;i++)
{
System.out.print(words[(i + words.length - rotation)%words.length] + " ");
}
}
}
}
I tried to change my if statement to a while statement but the code never outputs anything, it just keeps loading.