各位慕友們,這種多層循環(huán)怎么進行不了啊。
package ireader1;
//有1、2、3、4四個數(shù)字,能組成多少個互不相同且無重復數(shù)字的三位數(shù)?都是多少? ??
public class Lianxi11 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=0,b=0,c=0;
for(a=1;a<=4;a++){
for(b=1;b<=4&&a!=b;b++){
for(c=1;c<=4&&a!=c&&b!=c;c++){
System.out.println(a*100+b*10+c);
}
}
}
}
}
2017-06-29
判斷是否有重復的數(shù)字不應該放在循環(huán)判定條件內(nèi)
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ? int sum=0;
? ? ? ? int count=0;
? ? ? ?for(int a=1;a<5;a++){
? ? ? for(int b=1;b<5;b++){
? ? ? for(int c=1;c<5;c++){?
? ? ? if(a==b||a==c||b==c){
? ? ?continue;
? ? ? }else{
? ? ? sum=a*100+b*10+c;
? ? ? System.out.println(sum);
? ? ? count++;
? ? ? }
? ? ? }
? ? ? }
? ? ? ?}
? ? ?System.out.println("1,2,3,4可以組合成無重復的三位數(shù)個數(shù)為:"+count);
}