我想要做的是将@ 字符放在域之前。我还试图弄清楚如何将域设置为最后 4 个字符(例如 .com)。我该怎么做呢?任何帮助,将不胜感激。
我已经在这个链接上列出了我的工作。
来自链接的代码:
import java.util.Scanner;
public class Username {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Must be between 8 and 20 characters.");
System.out.println("Must contain at least one uppercase and lowercase letter.");
System.out.println("Must contain at least one digit. ");
System.out.println("Must contain a special character ] [ ? / < ~ # ! $ % ^ & * ( ) + = } | : ; , > { ");
System.out.println("Must contain @ before the domain");
System.out.println("The only acceptable domains are .com .edu .org .mil .gov .net");
System.out.println("\\n____Please enter your username to access the page. Follow the rules above.____ ");
String input = keyboard.nextLine();
while ((input.length() < 8) || (input.length() > 20))
{
System.out.println("Error! Your input is not valid.");
System.out.println("Please try again.");
keyboard.nextLine();
}
for (int i = 0; i <= input.length(); i++)
{
if(Character.isUpperCase(input.charAt(i)))
{
break;
}
else
{
if(i == input.length())
{
System.out.println("Error: Try again");
input = keyboard.nextLine();
}
}
}
for (int i = 0; i <= input.length(); i++)
{
if(Character.isLowerCase(input.charAt(i)))
{
break;
}
else
{
if(i == input.length())
{
System.out.println("Try again");
input = keyboard.nextLine();
}
}
}
char [] numbers= {\'0\',\'1\',\'2\',\'3\', \'4\',\'5\',\'6\',\'7\',\'8\',\'9\'};
char[] inputArray = input.toCharArray();
for (int i = 0; i < inputArray.length; i++)
{
for (int j = 0; j < numbers.length; j++)
{
if (inputArray[i]== numbers[j])
{
i=inputArray.length;
j=numbers.length;
}
else
{
if(i == inputArray.length-1 && j== numbers.length-1)
{
System.out.println("Try again");
input = keyboard.nextLine();
}
}
}
char [] SpecialCharacter = {\']\',\'[\',\'?\',\'/\',\'<\',\'~\',\'#\',\'.\',\'!\',\'$\',\'%\',\'^\',\'&\',\'*\',\'(\',\')\',\'+\',\'=\',\'}\',\'|\',\'>\',\'{\' };
char[] inputArray2 = input.toCharArray();
for (int k = 0; k < inputArray2.length; k++)
{
for (int l = 0; l < SpecialCharacter.length; l++)
{
if (inputArray2[k]== SpecialCharacter[l])
{
k=inputArray2.length;
l=SpecialCharacter.length;
}
else
{
if(k == inputArray2.length-1 && l == SpecialCharacter.length-1)
{
System.out.println("No...Try Again");
input = keyboard.nextLine();
}
}
}
String domain1 = ".com";
String domain2 = ".edu";
String domain3 = ".org";
String domain4 = ".mil";
String domain5 = ".gov";
String domain6 = ".net";
}
}
}
}