一个随机验证码且不重复的小程序以及求随机输入一组数组中的最大值(Java)...

1.代码:

package day20181015;
import java.util.Arrays;
/**
* 验证码的实现
* @author Administrator
*/
public class ArrayDemo {
public static void main(String[] args) {
/* 存放所有验证码的字符串 */
String[] pool = { "0", "1", "2", "3", "4", "5", "6", "7", "A", "B",
"C", "F", "T", "S" };// 下标 0~pool.length-1
// 标记上面pool中的元素是否被取过
boolean[] used = new boolean[pool.length];
// 存放验证码
String[] code = new String[6];
int i = 0;// code下标
// 循环产生验证码
while (true) {
// 随机下标
int index = (int) (Math.random() * pool.length);
if (used[index]) {// 字符串被取出过
continue;
}
used[index] = true;
code[i++] = pool[index];// 将随机出来的字符串存放到数组中
if ( i== 6) {
break;
}
}
System.out.println("验证码:" + Arrays.toString(code));
}
}

2.代码‘:

package day20181016;
import java.util.Scanner;
public class MaxDataDemo {
public static void main(String[] args) {
Scanner input=new Scanner(System.in);
int[]scores=new int[5];
for(int i=0;i<scores.length;i++){
System.out.print("请输入第"+(i+1)+"次成绩:");
scores[i]=input.nextInt();
}
int maxScore=scores[0];
for(int i=1;i<scores.length;i++){
if(scores[i]>maxScore){
maxScore=scores[i];
}
}
System.out.print("五门成绩的最高分为:"+maxScore);
}
}

转载于:https://www.cnblogs.com/SUN99bk/p/9808441.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值