Results 1 to 3 of 3
- 08-12-2011, 06:54 AM #1
Member
- Join Date
- Aug 2011
- Posts
- 1
- Rep Power
- 0
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:import java.io.*; public class StringManipulation { public static void main(String args []) throws IOException { BufferedReader dataIn=new BufferedReader(new InputStreamReader(System.in)); 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) { m.printStackTrace(); } } }
Enter First Name: John
Enter Middle Name: Jhay
Enter Last Name: Smith
Your Name Is: John Jhay Smith
Enter First Name: John
Enter Middle Name: Jhay
Enter Last Name: Smith
Your Name Is: John J. Smith
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?
- 08-12-2011, 08:14 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 787
- Rep Power
- 11
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\\.-]+")).....
- 08-12-2011, 08:39 AM #3Java Code:
Character.toString();
Java Code:if(!Character.isDigits())
but still gives out an error
Similar Threads
-
concatenate two char into one char
By nadissen in forum EclipseReplies: 3Last Post: 04-06-2011, 03:40 PM -
searching char array with another char array for full word matches
By karunabdc in forum New To JavaReplies: 2Last Post: 03-08-2011, 07:20 AM -
check a string char by char
By Sotsiak in forum New To JavaReplies: 2Last Post: 10-23-2010, 10:24 PM -
replaceALL(char oldChar, char newChar) method
By arson09 in forum New To JavaReplies: 0Last Post: 04-28-2010, 06:48 AM -
drawing char by char with Graphics
By diggitydoggz in forum New To JavaReplies: 5Last Post: 12-27-2008, 01:49 PM
Bookmarks