字符密码怎么写java

1.用JAVA编写输入用户名和密码import java.util.Scanner;
public class Test
{
public static void main(String []args)
{
String str1="青";
int num1=123;
Scanner scanner=new Scanner(System.in);
System.out.print("请输入名字:");
String str=scanner.next(); //获取字符串值
System.out.println("您输入的名字是:"+str);
if(str1==str)
{
System.out.println("对不起,你不是青2");
}
else
{
System.out.print("请输入密码:");
int num=scanner.nextInt(); //获取整数值
System.out.println("您输入的密码是:"+num);
if(num1==num)
{
System.out.println("欢迎你,青");
}
else
{
System.out.println("对不起,你不是青1");
}
}
}
}
2.java中如何输入一个字符import java.util.*;
public class Test_01
{
public static void main(String[] args)throws Exception
{
System.out.println("请输入一个字符");
char c=(char)System.in.read();
System.out.println(c);
}
}
扩展资料:
还可以输入字符串,输入字符串的方法
import java.io.*;
public class Test
{
public static void main(String[] args) throws IOException
{
BufferedReader buf = new BufferedReader (new InputStreamReader(System.in));
BufferedWriter buff = new BufferedWriter(new FileWriter("abc.txt"));
String str = buf.readLine();
while(!str.equals("exit"))
{
buff.write(str);
buff.newLine();
str = buf.readLine();
}
buf.close();
buff.close();
}
}
3.Java 写一个输入密码的小程序已完成,复制粘贴即可 。
import java.util.Scanner; public class YuGiOh { private static void checkPass ( String password ) { String regp = ".*[A-Z].*"; String rego = ".*[a-z].*"; String regq = ".*\\d.*"; String regs = ".*[\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\;\\:\\,\\.\\<\\>\\/\\?].*"; String regex = "^[a-zA-Z\\d\\`\\-\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\=\\[\\{\\}\\]\\;\\:\\,\\.\\<\\>\\/\\?]{6,}$"; String result = ""; if (password.length () < 6) { result += "\t\t-contain at least six characters. Your password is only " + password.length () + " characters long.\n"; } if (!password.matches (regp)) { result += "\t\t-contain at least one uppercase letter.\n"; } if (!password.matches (rego)) { result += "\t\t-contain at least one lowercase letter.\n"; } if (!password.matches (regq)) { result += "\t\t-contain at least one number.\n"; } if (!password.matches (regs)) { result += "\t\t-contain at least one of the following special characters: `[email protected]#$%^&*()_+=[{}];:,.<>/?\n"; } else if (!password.matches (regex)) { result += "\t\t-not contain an invalid character. The valid special characters: `[email protected]#$%^&*()_+=[{}];:,.<>/?\n"; } if (!"".equals (result)) { System.out.println ("Your password must:\n" + result); } else { System.out.println ("Your valid password is: " + password); } System.out.println (); } public static void main ( String[] args ) { Scanner scanner = new Scanner (System.in); while (true) { System.out.print ("Enter a valid password: "); String password = scanner.nextLine (); checkPass (password); } } } 。
4.java中如何输入一个字符晕,刚才回答了你的问题,题目没了……
实在不大想把代码重新再写一遍了 。实际上很简单 。Scanner 是可以用的 。读进来的是字符串,比如说保存在 str 。
str.charAt(0); 就是第一个字符 。括号里的数字就是 index 。把字符串就当数组看好了 。
还有一个解决方案就直接用 char c = (char)new BufferedReader(new InputStreamReader(System.in)).read();
就可以读取你输入的第一个字符 。
然后有了字符你就随便处理好了 。比如可以用 switch 语句: