- 输入一个学生的成绩,如果学习成绩>=90分的同学用A表示,60-89分之间用B表示,60分以下的用C表示(10)
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println(“请输入学生成绩:”);
Int grade = scanner.nextInt();
If(grade >=90){
System.out.println(‘A’);
}else if(grade >= 60){
System.out.println(‘B’);
}else{
System.out.println(‘C’);
}
}
- 编写一个java程序在屏幕上输出1!+2!+3!+……+10!的和(10)
public class test {
public static void main(String[] args) {
int sum = 0;
int res = 1;
for(int i = 1; i<=10;i++){
res = sum*i;
sum += res;
}
System.out.println("1!+2!+3!+……+10!的和是" + sum);
}
}
int [] arr1 = new int[3];
int [] arr2 = new int[4];
for(int i = 0;i <arr1.length;i++){
arr1[i] = (int)(Math.random()*10);
}
for(int i = 0;i <arr1.length;i++){
arr1[i] = (int)(Math.random()*10);
}
int[] arr3 = new int[arr1.length + arr2.length];
for (int i = 0; i < arr1.length; i++) {
arr3[i] = arr1[i];
}
for (int i = 0; i < arr2.length; i++) {
arr3[arr3.length+i-arr2.length] = arr2[i];
}
for(int i = 0;i < arr3.length - 1;i++){
for(int j = 0;j <arr3.length - i - 1;j++){
if(arr3[j] < arr3[j+1]){
int temp = arr3[j];
arr3[j] = arr3[j+1];
arr3[j+1] = temp;
}
}
}
System.out.println("合并后的数组是:");
for(int v:arr3){
System.out.print(v+"\t");
}
- 15个猴子围成一圈选大王,依次1-7循环报数,报到7的猴子被淘汰,直到最后一只猴子称为大王,问:哪只猴子会成为大王? 编写程序实现(20)
第五只称王
- 15个猴子围成一圈选大王,依次1-7循环报数,报到7的猴子被淘汰,直到最后一只猴子称为大王,问:哪只猴子会成为大王? 编写程序实现(20)
第五只称王
文章来源:https://www.toymoban.com/news/detail-591672.html
int monkeyCount = 15; int eliminateCount = 7; boolean[] monkeys = new boolean[monkeyCount]; for (int i = 0; i < monkeyCount; i++) { monkeys[i] = true; } int remainingMonkeys = monkeyCount; int currentIndex = 0; while (remainingMonkeys > 1) { int count = 0; while (count < eliminateCount) { if (monkeys[currentIndex]) { count++; } currentIndex = (currentIndex + 1) % monkeyCount; } monkeys[(currentIndex + monkeyCount - 1) % monkeyCount] = false; remainingMonkeys--; } int kingIndex = 0; while (!monkeys[kingIndex]) { kingIndex++; } int kingNumber = kingIndex + 1; System.out.println("最终的大王编号是:" + kingNumber);
int monkeyCount = 15; int eliminateCount = 7; boolean[] monkeys = new boolean[monkeyCount]; for (int i = 0; i < monkeyCount; i++) { monkeys[i] = true; } int remainingMonkeys = monkeyCount; int currentIndex = 0; while (remainingMonkeys > 1) { int count = 0; while (count < eliminateCount) { if (monkeys[currentIndex]) { count++; } currentIndex = (currentIndex + 1) % monkeyCount; } monkeys[(currentIndex + monkeyCount - 1) % monkeyCount] = false; remainingMonkeys--; } int kingIndex = 0; while (!monkeys[kingIndex]) { kingIndex++; } int kingNumber = kingIndex + 1; System.out.println("最终的大王编号是:" + kingNumber);
文章来源地址https://www.toymoban.com/news/detail-591672.html
到了这里,关于周考一之重做的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!