473,395 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How do I check chars in a string for predetermined criteria?

5
The program is supposed to accept a new password, but it needs to be at least 6 chars long and contain at least one number and one letter. The requirements do not say anything about special chars, so I assume they are not allowed. Unfortunately, the syntax seems sound, but the methods return an error: "illegal start of expression". public and static are pointed out. Otherwise, the rest of the code seems fine, so far. Any ideas? I'm new to Java, so I'm practicing with char and string manipulation and searching.

I am using jGrasp to compile. Here is my code so far. I am not too concerned about someone "stealing" my code as it's a project from a book, so I'm sending the whole thing. The error returned is "PasswordDahl.java:78: cannot find symbol
symbol : class string
location: class PasswordDahl
public static void TestLength(string password)
^
1 error"

Expand|Select|Wrap|Line Numbers
  1. import javax.swing.*;
  2. public class PasswordDahl{
  3.     public static void main(String[] args){
  4.         String password = JOptionPane.showInputDialog(null, "Enter a password between " +
  5.         "6 and 10 characters long using at least one number and one letter.");
  6.         TestLength(password);
  7.     }
  8.     public static void TestDigits(String password){
  9.         int i = 0;
  10.         char p;
  11.         boolean good;
  12.         while(i <= password.length()){
  13.             if(Character.isLetterOrDigit(i)){
  14.                 good = true;
  15.                 if(Character.isDigit(i)){
  16.                     good = true;
  17.                 }
  18.                 else if(Character.isLetter(i)){
  19.                     good = true;
  20.                     i = password.length();
  21.                 }
  22.                 else{
  23.                     good = false;
  24.                     JOptionPane.showInputDialog(null, "Be sure to include "
  25.                         + "\nat least one number and one letter. \nPlease try again.");
  26.                 }
  27.                     ++i;
  28.             }
  29.         }    
  30.     }
  31.     public static void TestLength(string password){
  32.         boolean good;
  33.         if(password.length() < (6) || password.length() > (10)){
  34.             JOptionPane.showInputDialog(null, "Your password is of insufficient length."
  35.                 + "\nIt must be between 6 and 10 characters long.\nPlease try again.");
  36.         }
  37.         else{
  38.             good = true;
  39.             TestDigits(password);
  40.         }
  41.     }
  42. }
Aug 14 '10 #1

✓ answered by Dheeraj Joshi

In line number 31
Expand|Select|Wrap|Line Numbers
  1. public static void TestLength(string password){
  2.  
Here you mentioned string not String (Not case of first letter).
String datatype starts with uppercase letter. not lower case.

So it must be

Expand|Select|Wrap|Line Numbers
  1. public static void TestLength(String password){
  2.  
Regards
Dheeraj Joshi

2 2206
Dheeraj Joshi
1,123 Expert 1GB
In line number 31
Expand|Select|Wrap|Line Numbers
  1. public static void TestLength(string password){
  2.  
Here you mentioned string not String (Not case of first letter).
String datatype starts with uppercase letter. not lower case.

So it must be

Expand|Select|Wrap|Line Numbers
  1. public static void TestLength(String password){
  2.  
Regards
Dheeraj Joshi
Aug 18 '10 #2
poijoy
5
I am so sorry for not getting back to you. Immediately after posting my question, my computers all died, so I was running around...again...figuring out a way to do my schoolwork, so I didn't get Bytes.com checked for my answer. Thank you very much. I really did have troubles with Java, so hopefully I'll be able to do it better next time I need to!

PoiJoy
Nov 5 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mvdevnull | last post by:
hey all currently i use the following piece of code to check if the string passed to me can be converted to base64, it is not very efficient and bad, can someone please suggest another of doing...
5
by: Rolan | last post by:
I have tried many iterations of constructing an expanded string link criteria for a list box selection, but have not been successful. The List Box uses a Totals Select Query that has a CustID,...
3
by: Ivan Demkovitch | last post by:
Hi! I would like to check if string contain specific substring. How to do it? P.S. I've done something stupid like String.Replace
3
by: trint | last post by:
How can I check this to see if it is a string representation of a number, or if it is actually just text? Convert.Int32(AlphaNumeric); returns the error for wrong format if it's alpha. I just...
6
by: ad | last post by:
How to check a string if this string is composite of number?
9
by: zjffdu | last post by:
I know in .net it is easy, but in C++ how can I check a string whether it is composed by backspace,\t,\n? Is there function can i call in the standard? thanks for any hint
2
by: NEMA | last post by:
How can i check the String letters? i have a textbox and will filled with numbers. i want to check if the number contain a '0' in font of the numbers, e.g. '090',i would like to cut the 1st '0',...
1
by: rahulhere | last post by:
Hai from csv file ,i want to check some string is there or not with some time stamp
10
by: Academia | last post by:
I'd like to check a string to see that it is a valid file name. Is there a Like pattern or RegEx that can do that. 1) Just the file name with maybe an extension 2)A full path An help...
16
by: skanemupp | last post by:
which is the best way to check if a string is an number or a char? could the 2nd example be very expensive timewise if i have to check a lot of strings? this value = raw_input() try:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.