/**
* This program prints things that are shifted
* Author: Peter.T
* created: 9/14/2017
*/
import java.util.*;
public class Shift//class header
{
public static void main(String[] args) {
boolean why = true;
int shift;
int place;
String encrypt = "";
Scanner scan = new Scanner(System.in);
String alpha = "abcdefghijklmnopqrstuvwxyz";
System.out.println("Please enter a word using the american alphabet.");
String word = scan.nextLine();
System.out.println("Please type by how much you want to shift the word.");
shift = scan.nextInt();
while(why==true){//restarts the program if user so choose
for(int i = 0;i<word.length();i++){
String index = word.substring(i,i+1);
place = alpha.indexOf(index);
int shifted = (place + shift)%26;
encrypt += alpha.substring(shifted,shifted+1);
}
System.out.println(encrypt);
System.out.println("do you want to shift another word or sentence? type 1 to play again and 2 to quit");
int num = scan.nextInt();
if(num==2){
why = false;
}
}
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.