How to determine if a username is correct? [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 months ago.
Improve this question
I need to determine if a username in the form of an email (something#something.com) is in the correct form. The necessary parameters for the username being correct are as follows:
there is something before the # symbol
there is text between the # symbol and the ".com"
the username ends in .com
These are the only parameters, if they are met the method will return true and if they are all not met it will return false.

public static boolean isCorrectUsername(String username){
var atPosition = username.indexOf("#");
return atPosition > 0 && username.endsWith(".com") && username.length() > atPosition + 5;
}

Related

ascii value as string to character in java [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have a String value "\u0004"
I need to convert it to character '\u0004'
I need to store this character back to the string.
How can this be done?
Maybe this is answer you want
// string value that has "\" in front
String s = "\\u0004";
// substring to leave "\u" out
char c = (char)Integer.parseInt(s.substring(2));

Replace all √num from a string java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have a string that contains String q = "What's the value of √32 and √83?";, my problem is replacing √num with sqrt(32) and sqrt(83).
That means my string should output : -
What's the value of sqrt(32) and sqrt(83)
is it possible?
Use a regex replacement on the pattern √(\d+)\b, and replace with sqrt(...):
String q = "What's the value of √32 and √83?";
String output = q.replaceAll("√(\\d+)\\b", "sqrt($1)");
System.out.println(output);
This prints:
What's the value of sqrt(32) and sqrt(83)?

assigning a char variable two values? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
This is what I want to happen:
char mirrorWords='x'||'w';
what I want to do with this is:
mirrorWords=='u'
returns false.
and
mirrorWords=='x'
returns true.
and
mirrorWords=='w'
returns true.
if this is possible how do I do it? And if not, well... thank you for your time.
update: I don't know why this is closed... I already accepted an answer.
No you cannot store more than one character in a single variable. However when you do the comparison you can do:
mirrorWords == 'w' || mirrorWords == 'x'
which will return true if either conditions is true, which sounds like what you want

How to find a string contains XXX-XXXXXX format? java [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I have a user input into a input box and want to find whether user entered the text format like 'XXX-XXXXXX'
How do I do this in java?
You could use split.
String str = "XXX-XXXXXX";
String[] words = str.split("-");
if(words[0].toCharArray().length == 3 && words[1].toCharArray().length == 6 && words.length == 2)
{
System.out.println("Correct");
}

Its not coming out of the loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi in the below code mandatoryCount = 0 and it should be increased when an image is selected but its found to be always 1 and i cant exit the loop can any one help me. Here if mandatoryCount = 0 or mandatoryCount>=imageTypeMandatory.length. It must come out of loop. But this code is working if i comment the mandatory count ==0. I cannot find the exact error.
if (dataOne.getCount() >= 1) {
mandatoryCount=0;
dataOne.moveToFirst();
while(!dataOne.isAfterLast()){
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){ if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++; imageTypeMandatoryCopy[iCopy]="";
}}
dataOne.moveToNext();
}
The logic is testing the moveFirst/moveNext.
if (dataOne.moveToFirst()) {
do {
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){
if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++;
imageTypeMandatoryCopy[iCopy]="";
}
}
} while(dataOne.moveToNext());
}

Categories