从1到50之中任意取5个数字之和为100的java代码
1个回答
展开全部
public static void main(String args[]){
int one,two,three,four,five;
do{
one = (int) (Math.random()*50)+1;
two = (int) (Math.random()*50)+1;
three = (int) (Math.random()*50)+1;
four = (int) (Math.random()*50)+1;
five = 100 - one - two - three - four;
}while(five<=0 || five>50);
System.out.println("one = "+one);
System.out.println("two = "+two);
System.out.println("three = "+three);
System.out.println("four = "+four);
System.out.println("five = "+five);
System.out.println("sum = "+(one+two+three+four+five));
}
int one,two,three,four,five;
do{
one = (int) (Math.random()*50)+1;
two = (int) (Math.random()*50)+1;
three = (int) (Math.random()*50)+1;
four = (int) (Math.random()*50)+1;
five = 100 - one - two - three - four;
}while(five<=0 || five>50);
System.out.println("one = "+one);
System.out.println("two = "+two);
System.out.println("three = "+three);
System.out.println("four = "+four);
System.out.println("five = "+five);
System.out.println("sum = "+(one+two+three+four+five));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询