I'm trying to code a deciphering program. I looked all over but I cannot figure out what is giving me the error. The code is supposed to take user Input, take a number (labeled key), then shift all characters in the string by that number. Any help would be greatly appreciated.
Here is my code:
import java.util.Scanner;
import java.io.*;
class Assignment3 {
public static void decipher(int key, String scanInput)
{
for (int x = 0; x < scanInput.length(); x++) {
int letterDecode = abc.indexOf(scanInput.charAt(x)) + key;
deciphered = deciphered + abc.charAt(letterDecode);
}
System.out.println(deciphered);
}
public static void main(String[] args)
{
Scanner scan = new scanner(System.in);
String abc = "abcdefghijklmnopqrstuvdxyzABCDEFGHIJKLMNOPQRSTUPWXYZ";
String deciphered = "";
System.out.println("Please enter your code below");
String scanInput = scan.nextLine();
System.out.println("Please enter your key (Preferrable from 1-26");
int key = scan.nextInt();
decipher();
}
}
These are the errors:
Assignment3.java:21: error: cannot find symbol
int letterDecode = abc.indexOf(scanInput.charAt(x)) + key;
^
symbol: variable abc
location: class Assignment3
Assignment3.java:22: error: cannot find symbol
deciphered = deciphered + abc.charAt(letterDecode);
^
symbol: variable deciphered
location: class Assignment3
Assignment3.java:22: error: cannot find symbol
deciphered = deciphered + abc.charAt(letterDecode);
^
symbol: variable deciphered
location: class Assignment3
Assignment3.java:22: error: cannot find symbol
deciphered = deciphered + abc.charAt(letterDecode);
^
symbol: variable abc
location: class Assignment3
Assignment3.java:25: error: cannot find symbol
System.out.println(deciphered);
^
symbol: variable deciphered
location: class Assignment3
Assignment3.java:32: error: cannot find symbol
Scanner scan = new scanner(System.in);
^
symbol: class scanner
location: class Assignment3
Assignment3.java:43: error: method decipher in class Assignment3 cannot be applied to given types;
decipher();
^
required: int,String
found: no arguments
reason: actual and formal argument lists differ in length
7 errors