Reputation: 11
I'm very new to java and to programing in general and I'm trying to figure out how to get this code to work.
What I need is to input a string then convert it to ascii and have the ascii values of each character shift by the value that was input and then convert it back to characters and print out the coded message. The last part is what I am having trouble with, I cant figure out how to get it back to characters.
P.S. this is my first posting so if I'm putting my code up wrong please let me know.
import java.util.Scanner;
public class
public static void main(String[] args)
{
Scanner stdIn = new Scanner(System.in);
System.out.println("Please enter text to encrypt");
String orignalText = stdIn.nextLine();
System.out.println("Please enter shift value");
int shiftValue = stdIn.nextInt();
for (int i=0; i<orignalText.length(); i++)
{
char c = orignalText.charAt(i);
char cUpper = Character.toUpperCase(c);
System.out.print((cUpper) + shiftValue);
}
}//end main
}//end class
Upvotes: 1
Views: 1174
Reputation: 10151
You have to cast it back ti a char
replace
System.out.print((cUpper) + shiftValue);
by
System.out.print((char)(cUpper + shiftValue));
Upvotes: 0