Note1:
郊区网站建设公司成都创新互联,郊区网站设计制作,有大型网站制作公司丰富经验。已为郊区成百上千家提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的郊区做网站的公司定做!
挑三个就用三个for-loop.
int[] a={1,2,3,4,5};
for(int i=1; ia.length-2; i++) {
for(j=1+1; ja.length-1; j++) {
for(k=j+1; ka.length; k++) {
System.out.println(a[i]+","+a[j]+","+a[k]);
}
}
}
Note2:
若挑出的个数要到执行期才得知, 就要改用别的做法.
可以将不定层数的for-loop转成一个for-loop.
如果不管排序的话递归 循环都能实现这个 给你一个分别用递归和循环实现的例子
import java.util.Arrays;
public class TestArray {
public static void main(String[] args) {
int[] a = { 1, 2, 3, 4, 5, 6, 7, 8};
System.out.println("***********循环*************");
ergodicArray(a, 6);
System.out.println("***********递归*************");
recursionArray(a,new int[6],0,0);
}
//递归
public static void recursionArray(int[] a,int[] b,int start,int index){
if(b.lengtha.length)
throw new RuntimeException("长度错误");
else{
if(indexb.length){
int[] c=b.clone();
for(int i=start;ia.length;i++){
//System.out.println("i:"+i+" index:"+index);
c[index]=a[i];
recursionArray(a,c,i+1,index+1);
}
}else
System.out.println(Arrays.toString(b));
}
}
//循环
public static void ergodicArray(int[] a,int length){
if(lengtha.length)
throw new RuntimeException("长度错误");
else{
int[] b=new int[length];
for(int i=0;ilength;i++)
b[i]=i;
ergodicArray(a,b);
}
}
public static void ergodicArray(int[] a, int[] b) {
while (b[0] = (a.length - b.length)) {
if (b[b.length - 1] a.length) {
for (int i = 0; i b.length; i++) {
System.out.print(a[b[i]]);
if(ib.length-1)
System.out.print(',');
}
System.out.println();
++b[b.length - 1];
} else {
int j = b.length - 1;
while (j = 0) {
if (b[j] != a.length - (b.length - j) + 1) {
// j--;
break;
} else
j--;
}
if ((b[0] == (a.length - b.length - 1) || b[j] = (a.length - b.length + j))) {
int t = 0;
for (int i = j; i b.length; i++) {
if (i == j) {
b[i]++;
} else {
b[i] = b[i - 1] + 1;
}
}
}
}
}
}
Fourth questions wrong, should be C, Java class
parameter list fifth questions wrong, goto is a reserved word Java, but also belongs to the keyword Java is not used, malloc is a variable named
sixth questions wrong, to initialize local variables, global variables have a default value of
8 B
10 C, the default variables belong to global variables value, and belongs to the static, available in the static method or the main method inside
12 D = is the comparison operator, with || logic operator, | is bitwise (binary)
13 A
14 B the default constructor is defined in your class, and no other constructors, define the parameter less constructor
15 B默认构造函数没有返回类型,系统,同名的类,不是静态的
16如果(改良薄噢乐安)需要的是值类型
17 C超载的方法的返回类型,与同一名称的第一个方法,类型或二参数个数不同,对点
因为题目要求拷贝Example1-10.java文件从Java_Source到Java目录下,可以把数字拼到文件名的字符串中,从而把Example1-10.java文件,一个一个复制到目标目录下.
完整的Java程序如下
import java.io.File;
import java.IoException;
public class test{
pubilc static void main(String args[])throws IoException{
for(int i=1;i=10;i++){
String S1 = "G:/Java_Source/Example"+i+".java";
String S2 = "G:/Java/Example"+i+".java";
File Source = new File(S1);
File dest = new File(S2);
java.nio.file.Files.copy(Source.toPath(),dest.toPath());
}
System.out.printIn("File copy");
}
}
是编译错误,数组越界,算法可以这:样实现:随机选数,把选好的数字放到一个表(数组)中;如果重复则反复执行。代码如下:
class Main {
public static void main(String args[]) {
final int N = 21;
final int M = 7;
int selected[] = new int[N];//用来记得每次选的数字表格
int cnt = 0;// 已选的数字个数
while (cnt M) {
int n = (int) (Math.random() * N) + 1;
boolean find = false;
for (int i = 0; i cnt; i++) {
if (selected[i] == n) {// 表示n重复
find = true;
break;
}
}
if (!find) {//表示选的n是不重复的
selected[cnt] = n;
cnt++;
}
}
for(int i=0;iM;i++)//打印每次选择的数字
System.out.print(selected[i]+" ");
}
}