I'm coming here with another question because I've ran into a snag and haven't been able to figure out what the issue is..
My problem: Create an array of 256 characters, and read a message character by character from keyboard and store them in the array up to 256 symbols. The method should return number of the characters stored in the array. Then pass the array to another method to print each word of the message in a line.
My attempted solution:
public static void main(String[] args){
char[] arrItem7 = new char[256];
readArray(arrItem7);
printOneInLine(arrItem7);
}
public static char[] getMsg(){
String myMessage;
System.out.print("Input Message: ");
Scanner input = new Scanner(System.in);
myMessage = input.nextLine();// Read a line of message
return myMessage.toCharArray();
}
public static char[] readArray(char[] arr){
arr = getMsg();
return arr;
}
public static void printOneInLine(char[] arr){
for(int i = 0; i < arr.length; i++){
if(arr[i] == 0){
System.out.print(" ");
}else{
System.out.print(arr[i]);
}
}
System.out.println();
}
The program prompts for input but then, unfortunately, prints NULL. I must be doing something wrong when setting the array to my message method.. Can someone help me? I've been trying to wrack my brain for the past 20 minutes.. Thanks so much