Results 1 to 3 of 3
  1. #1
    xLrak is offline Member
    Join Date
    Aug 2011
    Rep Power

    Post stuck on this pls help(validation and char.toString)

    we were asked by our professor to do a simple class wherein we need to make it ask the user to enter the first name middle name and last name so i came up with the class like this:

    Java Code:
    public class StringManipulation {
    	public static void main(String args []) throws IOException {
    		BufferedReader dataIn=new BufferedReader(new InputStreamReader(;
    		try {
    			System.out.print("Enter First Name: ");
    			String k = dataIn.readLine();
    			System.out.print("Enter Middle Name: ");
    			String j = dataIn.readLine();
    			String m = Character.toString();
    			System.out.print("Enter Last Name: ");
    		 	String s = dataIn.readLine();
    		System.out.println(k + " " + j + " " + s);		
    		}catch(Exception m) {
    the output is always like this:

    Enter First Name: John
    Enter Middle Name: Jhay
    Enter Last Name: Smith
    Your Name Is: John Jhay Smith
    but then after that when i showed it to her she wants me to make the final output to be like this:

    Enter First Name: John
    Enter Middle Name: Jhay
    Enter Last Name: Smith
    Your Name Is: John J. Smith
    how can i make it like that? i used char.toString code but i always come up with an error and no matter what i do i can't seem to fix it.

    also she wants me to make a validation code for it where in the user can only input alphabets and the special characters "." and "-" i tried using if(!Character.isDigits()) but still gives out an error .. can anyone help?

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Rep Power


    String m = Character.toString(); <-- what ?
    You could use charAt(0) to get the first Character, thats what you want or?
    char m =j.charAt(0);
    System.out.println(k + " " + m + ". " + s);

    For the other one you could use regex,something like if(k.matches("[a-zA-Z\\.-]+")).....

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Rep Power


    Java Code:
    The toString method will convert a char to a String which is not what you want. Even if it was, which char is it supposed to convert to a String? Did you look at the API to see what parameters that method has?
    Java Code:
    Once again did you read the API to see if the Character class has that method. You cannot just make up method names.
    but still gives out an error
    In future copy and paste the full and exact error message so we can see it. We don't read minds.

Similar Threads

  1. concatenate two char into one char
    By nadissen in forum Eclipse
    Replies: 3
    Last Post: 04-06-2011, 02:40 PM
  2. Replies: 2
    Last Post: 03-08-2011, 06:20 AM
  3. check a string char by char
    By Sotsiak in forum New To Java
    Replies: 2
    Last Post: 10-23-2010, 09:24 PM
  4. replaceALL(char oldChar, char newChar) method
    By arson09 in forum New To Java
    Replies: 0
    Last Post: 04-28-2010, 05:48 AM
  5. drawing char by char with Graphics
    By diggitydoggz in forum New To Java
    Replies: 5
    Last Post: 12-27-2008, 12:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts