Why wont this compile its killing me. (java)
Posted
by Ryan The Leach
on Stack Overflow
See other posts from Stack Overflow
or by Ryan The Leach
Published on 2010-03-31T13:28:48Z
Indexed on
2010/03/31
13:33 UTC
Read the original article
Hit count: 319
java
import java.util.*;
public class Caesar
{
public static void main(String [] args)
{
final boolean DEBUG = false;
System.out.println("Welcome to the Caesar Cypher");
System.out.println("----------------------------");
Scanner keyboard = new Scanner (System.in);
System.out.print("Enter a String : ");
String plainText = keyboard.nextLine();
System.out.print("Enter an offset: ");
int offset = keyboard.nextInt();
String cipherText = "";
for(int i=0;i<plainText.length();i++)
{
int chVal = plainText.charAt(i);
if (DEBUG) {int debugchVal = chVal;}
chVal +=offset;
if (DEBUG) {System.out.print(chVal + "\t");}
while (chVal <32 || chVal > 127)
{
if (chVal < 32) chVal += 96;
if (chVal > 127) chVal -= 96;
if(DEBUG) {System.out.print(chVal+" ");}
}
if (DEBUG) {System.out.println();}
char c = (char) chVal;
cipherText = cipherText + c;
if (DEBUG) {System.out.println(i + "\t" + debugchVal + "\t" + chVal + "\t" + c + "\t" + cipherText);}
}
System.out.println(cipherText);
}
}
© Stack Overflow or respective owner