早教吧 育儿知识 作业答案 考试题库 百科 知识分享

javafor循环的计算题题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?

题目详情
java for循环的计算题
题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
▼优质解答
答案和解析
package mypackage;
//有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少
public class circle {
public void method1()
{
int[] a=new int[method2()];
int count=0;
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
for(int t=1;t<5;t++)
{
if((i==j)&&(j==t))
{
break;
}
else
{
a[count]=i*100+j*10+t;
System.out.println(a[count]);
count++;
}
}
}
}
System.out.println(count);
}
public int method2()
{
int count=0;
for(int i=1;i<5;i++)
{
for(int j=1;j<5;j++)
{
for(int t=1;t<5;t++)
{
if((i==j)&&(j==t))
{
break;
}
else
count++;
}
}
}
return count;
}
public static void main(String[] args)
{
circle o=new circle();
o.method1();
}
}