Question: i have a question about a java program i am trying to run. whenever i try to run my code i get this error message.
i have a question about a java program i am trying to run.
whenever i try to run my code i get this error message. Can you explain to me why i get this message and how i can fix it?
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.skip(Scanner.java:1732) at java.util.Scanner.skip(Scanner.java:1749) at Problem2.main(Problem2.java:16)
this is my code
import java.util.Scanner; import java.io.*;
public class Problem2 { public static void main(String[] args)throws FileNotFoundException { Scanner input = new Scanner(new File(args[0])); int nk = input.nextInt(); int setK[] = new int[nk]; for(int i=0;i setK[i] = input.nextInt(); input.skip(" "); String msg = input.nextLine(); input.nextInt(); String emsg = encryptMessage(setK, msg); System.out.println(emsg); input.close(); }
public static String encryptMessage(int[] secretKeys, String message){ String enc = ""; for(int i=0;i int idx = message.charAt(i) - 'a'; int pos = (idx + secretKeys[i]) % 26; char c = (char) ('a' + pos); enc += c; } return enc; } }
given
problem2.txt
3 1 2 3 bzy -1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
