public class file { public void _copy(int[] to, int[] from, int count) { int n = (count + 7) / 8; int i = 0; int j = 0; do { switch (count % 8) { case 0: to[i++] = from[j++]; case 8: to[i++] = from[j++]; case 7: to[i++] = from[j++]; case 6: to[i++] = from[j++]; case 5: to[i++] = from[j++]; case 4: to[i++] = from[j++]; case 3: to[i++] = from[j++]; case 2: to[i++] = from[j++]; case 1: to[i++] = from[j++]; } } while (--n > 0); } public static void main(String[] args) { file f = new file(); int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; int b[] = new int[10]; f._copy(b, a, 10); for (int i = 0; i < 10; i++) System.out.println(b[i]); } }这样做不行啊,能运行,但结果不正确的. 我想解决的是这个问题:switch(xxx){ case 0: do{ case 1: case 2: } }while(xxx);也就是上面那个C程序的语句嵌套的问题,想不出解决办法 希望高手指点!!!
switch(xxx){ case 0: do{ case 1: case 2: } }while(xxx);这样的写法是不正确的,c/c++里也不行。switch和do/while的语法java 和 c/c++一样
public void _copy(int[] to, int[] from, int count) {
int n = (count + 7) / 8;
int i = 0;
int j = 0;
do {
switch (count % 8) {
case 0:
to[i++] = from[j++];
case 8:
to[i++] = from[j++];
case 7:
to[i++] = from[j++];
case 6:
to[i++] = from[j++];
case 5:
to[i++] = from[j++];
case 4:
to[i++] = from[j++];
case 3:
to[i++] = from[j++];
case 2:
to[i++] = from[j++];
case 1:
to[i++] = from[j++];
}
} while (--n > 0); } public static void main(String[] args) {
file f = new file();
int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int b[] = new int[10];
f._copy(b, a, 10);
for (int i = 0; i < 10; i++)
System.out.println(b[i]);
}
}这样做不行啊,能运行,但结果不正确的.
我想解决的是这个问题:switch(xxx){
case 0:
do{
case 1:
case 2:
}
}while(xxx);也就是上面那个C程序的语句嵌套的问题,想不出解决办法
希望高手指点!!!
case 0:
do{
case 1:
case 2:
}
}while(xxx);这样的写法是不正确的,c/c++里也不行。switch和do/while的语法java 和 c/c++一样