要求,编写一个程序,模拟默认密码的自动生成策略,手动输入用户名,根据用户名自动生成默认密码。在生成密码时,将用户名反转即为默认的密码
public static void main(String[] args) {
System.out.println("请输入用户名:");
Scanner scan = new Scanner(System.in);
String name = scan.nextLine();
String pasword = reverse(name);
System.out.println("用户名为"+name+"的用户的默认密码为:"+pasword);
}
//将用户名反转
public static String reverse(String str) {
return new StringBuilder(str).reverse().toString();
}
控制台打印:
请输入用户名:
abc123
用户名为abc123的用户的默认密码为:321cba