Page 1 of 1

.charAt method

Posted: Fri Jun 01, 2018 12:46 pm
by ajnudnyg@gmail.com

Code: Select all

//java
import java.util.Scanner;
public class Separator{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        System.out.println("Please put in a message");
        //user's message
        String message = input.next();
        //finds how long message is
        for(int i=0; i<message.length(); i++){
            //prints out character at each location in order
            System.out.println(message.charAt(i));
        }
    }
}
Hi, all this works, but when the message that the user inputs has a space, it skips it and parts of the message after the space won't print out either.

Re: .charAt method

Posted: Wed Jun 06, 2018 5:17 pm
by dbremmen@gmail.com
Hi!
You need to use input.nextLine() instead of input.next() to get the whole line for input
Regards!
David