HELP ME~~~
看书遇到的小题目:
编写一个显示从6种早餐中随机选择一种的程序(你可以使用任意的套餐,比如:炒蛋.鸡蛋饼.水果.麦粥.土司或者酸奶).
想了想用Math.random()*10+1产生的是1-10,用Math.random()/2*10+1产生的是1-5,就是6没办法,请各位帮帮我
int randomNum=(int)(Math.random()*(upperBound-lowerBound+1)+lowerBound);
//this will generate a number between lowerBound to upperBound(inclusive)
in your case: int breakfast = (int)(Math.random()*6;
each breakfast is represented by 0 1 2 3 4 5
Question:Why do you need to start from 1? you can make one 0 right? :-)
Switch will be a good idea here:)
int final EGG = 0, EGGTHING = 1, FRUIT=2,RICE=3,BRAKE = 4,MILK=5;