Ok I have \"the different shift and decrypt value\" that works in this program,S
ID: 3532458 • Letter: O
Question
Ok I have "the different shift and decrypt value" that works in this program,So my question is
I need help to get the program to also return where "all the letters stay the same" and also where if I type out "This is a test" it will return "no spaces between the words"
import java.util.*;
public class YourNameProg3
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please enter text to encrypt");//plain text
String word = in.nextLine();
System.out.println("Please enter shift value :");//enter a number to be shifted either + or -
int shift = in.nextInt();
in.nextLine();
System.out.println("Encrypted text is " + shifter(word, shift));
System.out.println("Please enter text to decrypt");//can cypher out crypted text
word = in.nextLine();
System.out.println("Please enter shift value :");//enter a number to be shifted either + or -
shift = in.nextInt();
in.nextLine();
System.out.println(shifter(word, shift));
}
//Encrypts the parameter with the given shift
public static String shifter(String word, int shift)
{
String output = "";
word = word.toUpperCase();
for(char c : word.toCharArray())// only encrypt letters
if(Character.isLetter(c))
output += (char)('A'+(c-'A'-shift+26)&);
else
output += c;
return output;
}
}//end class
Explanation / Answer
updated your code:
check output here: http://ideone.com/XFt9Rp
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.