用ascii表的密码生成器的Java程序如下
import java.util.Scanner;
public class C {
public static void main(String []args) {
int n,m,num;
System.out.print("请输入(位数,个数):");
Scanner sc=new Scanner(System.in);
m=sc.nextInt();
n=sc.nextInt();
char a[]=new char[3];
for (int i=0;i
String s="";
for(int j=0;j
a[0] = (char) ((int)(Math.random() * 26) + 'a');
a[1] = (char) ((int)(Math.random() * 26) + 'A');
a[2] = (char) ((int)(Math.random() * 10) + '0');
num=(int)(Math.random() * 3);
s=s+a[num];
}
System.out.println(s);
}
}
}
初学者的代码(刚学一星期....)
package ahhhh;
import java.util.*;
public class Suiji {
public static void main(String[] args) { System.out.print("请输入密码位数");
Scanner s=new Scanner(System.in);
int i=s.nextInt();
System.out.print("请输入密码个数");
Scanner m=new Scanner(System.in);
int j=m.nextInt();
int a=1,b=0;
char c1,c2;
for(int d=1;d<=j;d++) {
int sum=0;
while(true) {
int c=(int)(Math.random()*123);
if(c>='A'&&c<='Z') {
c1=(char)c;
System.out.print(c1);
sum+=1;
}else if(c>='a'&&c<='z'){
c2=(char)c;
System.out.print(c2);
sum+=1;
}else if(c>=0&&c<=9) {
b=c;
System.out.print(b);
sum+=1;
}
a++;
if(sum==i){
break;