need help with scanner
im currently writting a program with the aim of encoding a string.
"The program is to implement a simple encryption program. The user will be asked four questions:
• The String they wish to have encoded (which may contain spaces).
• The character you'd like used to seperate words in the output (to be stored in a char).
• The number of letters to shift each letter by (to be stored in an int variable).
• Whether or not punctuation is to be repeated in the output (to be stored in a boolean variable).
The answers to these questions will be used to encrypt the given uncoded string (once it has been capitalised), and the resulting coded string will be displayed on the screen."
so far i have managed to come up with this;
and i am unable to figure out how to change the ascii values of the letters in the string. im guessing i need to convert the string to a char???
public class AssigOne108
public static void main(String args)
String word, delimiter, punc;
int shiftAmount, length, rightPos;
char punc1, delim, text, letter;
System.out.println("enter a word/phrase that you wish to encrypt");
word = sc.nextLine();
System.out.println("enter your desired delimiter");
delimiter = sc.nextLine();
delim = delimiter.charAt(0);
System.out.println("enter the number of letters to shift the code");
shiftAmount = sc.nextInt();
System.out.println("would you like to include punctuation? true/false");
pass = sc.nextBoolean();}
word = word.toUpperCase();}
This is one of the things i miss about C++. Strings are just arrays of characters, but more advanced. Anyways, you've got it right. Just do a toCharArray, do your manipulation, then convert it back to a string. Nice and simple.