「java糖果」java糖果传递
今天给各位分享java糖果的知识,其中也会对java糖果传递进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
java买不到的数目 小明开了一家糖果店。他别出心裁:把水果糖包成4颗一包和7颗一包的两
1、首先我来整理下这到题,抽取主要提干
a=4 和 b=7 最大不能组合出来的数是c= 17
a=3 和 b=5 最大不能组合出来的数是c= 7
当a b值任意 求c值
2、java 代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class T_1796140699890495867html {
public static void main(String[] args) throws Exception {
//输出段
BufferedReader brKey = new BufferedReader(new InputStreamReader(System.in));
System.out.println("用户输入:");
String strNum = brKey.readLine();
String[] oneAndTwoNums = strNum.split(" ");
brKey.close();
//处理段
int boxOne,boxTwo,impNum,bufNum;
boxOne = Integer.valueOf(oneAndTwoNums[0]);
boxTwo = Integer.valueOf(oneAndTwoNums[1]);
//如果第一个数大于第二个数,那么调换位置
if(boxTwo boxOne){
boxOne = boxOne + boxTwo;
boxTwo = boxOne - boxTwo;
boxOne = boxOne - boxTwo;
}
//预定义值
impNum = boxOne * boxTwo;
//临时计算数
bufNum = impNum;
while(bufNum = 0){
if(bufNum % boxOne == 0){
bufNum = (-- impNum);
}else if(bufNum % boxTwo == 0){
bufNum = -- impNum;
}else{
bufNum -= boxTwo;
}
}
//输出段
System.out.println("程序应该输出:");
System.out.println(impNum);
}
}
3、运行截图
HDOJ 1205吃糖果 java
/**
* @(#)Eat_Candy.java
*
*
* @author
* @version 1.00 2013/10/17
*/
import java.util.*;
import java.math.*;
public class Eat_Candy {
/**
* Creates a new instance of codeEat_Candy/code.
*/
// public Eat_Candy() {
// }
/**
* @param args
* the command line arguments
*/
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
long number = reader.nextLong();
long size = reader.nextLong();
long sum = 0, max = 0, b = 0;
b = reader.nextLong();
for (long j = 0; j number; j++) {
if (size 0 || size 1000000)
break;
for (long i = 0; i size; i++) {
sum += b;
if (b max) {
max = b;
}
}
if (sum - max + 1l = max) {
System.out.println("YES");
} else
System.out.println("NO");
}
// TODO code application logic here
}
}
求助:java中怎么实现按比例随机分配
比如有十个糖果,按照2:3:5的比例分配给三个小孩
public class luck {
public static ListString candy = new ArrayListString();
public static ListString child1 = new ArrayListString();
public static ListString child2 = new ArrayListString();
public static ListString child3 = new ArrayListString();
// 2:3:5
public static void main(String[] args) {
candy.add("糖果1");
candy.add("糖果2");
candy.add("糖果3");
candy.add("糖果4");
candy.add("糖果5");
candy.add("糖果6");
candy.add("糖果7");
candy.add("糖果8");
candy.add("糖果9");
candy.add("糖果10");
int count = 10;
for (int i = 0; i 2; i++) {
int math = (int) (Math.random() * count);
child1.add(candy.get(math));
candy.remove(math);
count--;
}
for (int i = 0; i 3; i++) {
int math = (int) (Math.random() * count);
child2.add(candy.get(math));
candy.remove(math);
count--;
}
for (int i = 0; i 5; i++) {
int math = (int) (Math.random() * count);
child3.add(candy.get(math));
candy.remove(math);
count--;
}
System.out.println("child1的糖:");
for (int i = 0; i child1.size(); i++) {
System.out.println(child1.get(i));
}
System.out.println("child2的糖:");
for (int i = 0; i child2.size(); i++) {
System.out.println(child2.get(i));
}
System.out.println("child3的糖:");
for (int i = 0; i child3.size(); i++) {
System.out.println(child3.get(i));
}
}
}
输出结果:
child1的糖:
糖果6
糖果1
child2的糖:
糖果7
糖果2
糖果8
child3的糖:
糖果4
糖果3
糖果10
糖果5
糖果9
java糖果的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java糖果传递、java糖果的信息别忘了在本站进行查找喔。