Start New Discussion within our Software Development Community

I'm just playing around with some code and I can't figure out why this isn't working. It's only "encrypting" one word. Can anyone tell me what's wrong with it?

import java.util.*;

public class EncrypterDriver {
	static String encrypt(String fileMessage)
		String encryptedMessage = "";
		char fileChar = '0';
		String fileWord = "";
		String encryptedWord;
		StringTokenizer st = new StringTokenizer(fileMessage);
		while(st.hasMoreTokens())								//While the fileMessage string has more words in it
			fileWord = st.nextToken();						//Returns word from the fileMessage string and stores it in fileWord
			encryptedWord = "";							//Resets encrypted word
			for(int i = 0; i < fileWord.length() - 1; i++)			//loops through each character in the fileWord string
				fileChar = fileWord.charAt(i);						// returns the character at position "i" from the string fileWord
				fileChar+= 10;										// adds 10 to the character
				encryptedWord +=  fileChar;				// puts the character in the String encryptedMessage
			encryptedMessage += encryptedWord + " ";							//stores a word in encrypted word and inserts a space after every word encrypted
		return encryptedMessage;

	public static void main(String[] args) {
		String message = "";
		String encryptedMessage = "";
		Scanner sc = new Scanner(;
		System.out.println("Enter a message: ");
		message =;
		encryptedMessage = encrypt(message);



You are only reading a single word here

message =;

Use nextLine() to read the entire input line

message = sc.nextLine();
This article has been dead for over six months. Start a new discussion instead.