Results 1 to 3 of 3
Thread: Char troubles
- 11-10-2009, 03:16 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
Char troubles
Hello, i'm pretty new to the Java programming language and it seems I have run into a brick wall with the char type.
I have written a program which translates a simple string of numbers into morse code. However, that part works perfectly, but my input validation seems to be incorrect in some way. I am constantly getting this message at compile time:
To put this in better context, here is the rest of the code:Java Code:Question_1.java:22: char cannot be dereferenced if (input.charAt(i).isDigit() == false) { ^
Any help with this would be greatly appreciated, thanks in advanceJava Code:import javax.swing.JOptionPane; public class Question_1 { public static void main(String[] arg) { //Get the input String input = JOptionPane.showInputDialog("Enter a series of numbers: "); //Translate input and get rid of white space to the left and right of the string input = input.replaceAll("0"," -----"); input = input.replaceAll("1"," .----"); input = input.replaceAll("2"," ..---"); input = input.replaceAll("3"," ...--"); input = input.replaceAll("4"," ....-"); input = input.replaceAll("5"," ....."); input = input.replaceAll("6"," -...."); input = input.replaceAll("7"," --..."); input = input.replaceAll("8"," ---.."); input = input.replaceAll("9"," ----."); input = input.trim(); //Validation for (int i = 0; i <= input.length(); i++){ if (input.charAt(i).isDigit() == false) { JOptionPane.showMessageDialog(null,("Non numeric characters are not a valid input"),"Error", JOptionPane.INFORMATION_MESSAGE); break; } } //Output the results JOptionPane.showMessageDialog(null,("The morse code is: "+input),"Morse Code", JOptionPane.INFORMATION_MESSAGE); } }
Edit:
Something I forgot to add; the validation is checking for non numerical values in the string by iterating through each character, if found it will ouput an error message.Last edited by diggdude; 11-10-2009 at 03:19 PM.
- 11-10-2009, 03:21 PM #2
Java Code:if(!Character.isDigit(input.charAt(0))){Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-10-2009, 03:55 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Integer troubles
By Tb0h in forum New To JavaReplies: 11Last Post: 08-13-2009, 04:56 PM -
Gif decoding/LZW troubles
By hellochar in forum Advanced JavaReplies: 2Last Post: 07-14-2009, 11:26 PM -
Image troubles
By Theodoreb in forum New To JavaReplies: 24Last Post: 07-14-2009, 12:41 AM -
subclass troubles
By xf021209 in forum New To JavaReplies: 12Last Post: 04-20-2009, 11:46 PM -
drawing char by char with Graphics
By diggitydoggz in forum New To JavaReplies: 5Last Post: 12-27-2008, 12:49 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks