内容发布更新时间 : 2025/6/26 5:24:19星期一 下面是文章的全部内容请认真阅读。
for(int i=0; i
for(int i=0; i
int max =a[0], min = a[0]; for(int i=0; i
if(a[i] < min) { min = a[i]; idx2 = i; } }
if(idx1 != 0) { int temp = a[0]; a[0] = a[idx1]; a[idx1] = temp; }
if(idx2 != N-1) { int temp = a[N-1]; a[N-1] = a[idx2]; a[idx2] = temp; }
for(int i=0; i
【程序36】
题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数
public class lianxi36 {
public static void main(String[] args) { int N =10;
int[] a = new int[N];
Scanner s = new Scanner(System.in);
for(int i=0; i
for(int i=0; i
int m = s.nextInt(); int[] b = new int[m]; for(int i=0; i
for(int i=N-1; i>=m; i--) { a[i] = a[i-m]; }
for(int i=0; i
for(int i=0; i
【程序37】
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。
public class lianxi37 {
public static void main(String[] args) { Scanner s = new Scanner(System.in);
int n = s.nextInt();
boolean[] arr = new boolean[n]; for(int i=0; i
int leftCount = n; int countNum = 0; int index = 0; while(leftCount > 1) { if(arr[index] == true) { countNum ++; if(countNum == 3) { countNum =0; arr[index] = false; leftCount --; } }
index ++; if(index == n) {
index = 0; } }
for(int i=0; i
【程序38】
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。 /*………………
*……题目意思似乎不能用length()函数 */ import java.util.*; public class lianxi38 {
public static void main(String[] args) { Scanner s = new Scanner(System.in);
String str = s.nextLine(); } } 【程序39】