I'm trying to write a program that checks if a input string value contains any capital letters. Is there a way to do this in java?
jhamill
0
Newbie Poster
Recommended Answers
Jump to Postmake an array of chars, filled with all the possible capitals, iterate over this array and check if the string contains the char ...
the .contains method could do that for you
Jump to PostIf you just want a boolean to see if it had any capitals, you can use this:
String test1 = "Hello"// your string; String test2 = test1.toLowerCase(); boolean hasCapital = !test1.equals(test2);
Jump to Posti guess I should be a little more specific the boolean method needs to take a String argument and return true if it has at least one upper case letter and false otherwise
Which is exactly what I gave you..?
public static boolean checkForCapital(String s){ return !s.equals(s.toLowerCase()); …
Jump to Post@CSCIHelper1111: You just gave him a function checkForCapitals which takes a String for an argument, but you don't even use it, and do what I did in 6 times as much code, while I even gave him the function which he just had to copy paste.
If you reply …
All 13 Replies
stultuske
1,116
Posting Maven
Featured Poster
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
jhamill
0
Newbie Poster
Aviras
5
Junior Poster in Training
jhamill
0
Newbie Poster
jhamill
0
Newbie Poster
Aviras
5
Junior Poster in Training
jhamill
commented:
this was the most helpful post, this user clearly knows what he is doing
+1
CSCIHelper1111
-6
Newbie Poster
Aviras
5
Junior Poster in Training
CSCIHelper1111
-6
Newbie Poster
JamesCherrill
commented:
Personal insult.
-3
stultuske
commented:
rude, uncalled for and proof that you don't respect the forum rules.
-2
Aviras
commented:
uncalled for, even besides the poster thinking otherwise
-1
stultuske
1,116
Posting Maven
Featured Poster
malli_twiter
0
Newbie Poster
stultuske
1,116
Posting Maven
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.