新手提问,老师布置的作业,我没有一点思路
下面是题目:1,(挑战)输入一个整数:分别输出“该数的个,十,百”数;如输入:1453;则输出“3,5,4,1";
解题提示:将一个数模10,可以得该数的个位,模100,可以得该数的十位;
将一个数除10,可以得到该数
2,模拟实现中央二台的:高了,低了节目;
为一个商品产生一个1000内的随机价格的整数,
然后循环的输入一个整数;如果该数大于商品价格,则输出“高了”,
否则输出“低了”,直到输入的数等于商品价格,最后输出“恭喜!!!你用了x次就猜对了";
3:游戏说明:
循环的让电脑出拳,人出拳,直到用户输入“退出”止,并统计出人,机的输赢情况;
具体说明:
一开始输出:“游戏开始吗?”,如果输入的是"开始“,则机器开始先出拳,后人出拳;
并运算输赢结果,打印“XX赢了”, 并接着输出“要继续吗?”,如果输入"继续",则
则机器开始先出拳,后人出拳,并运算输赢结果,打印“XX赢了”,如此循环,直到输
入”退出“为止; 最后统计出人,机的输赢情况;
总共是:a次,
人 赢:x次,
机器赢: y次,
平 局:z次
4、一个球从100m高度自由落下,每次落地后反弹回原来高度的一半,再落下。求它在第10次落地并反弹到最高点,共经过多少m?第10次反弹多高?
搜索更多相关的解决方案:
用户
----------------解决方案--------------------------------------------------------
程序代码:
import java.util.*;
public class Questions {
Scanner reader = new Scanner(System.in);
public int get(int num, int index) {
if(num < 0 || index < 0 || index > (int)Math.log10(num))
return - 1;
int i = (int)Math.ceil(Math.pow(10, index));
return num / i % 10;
}
public Questions question1() {
System.out.println("Question1:");
int num = reader.nextInt();
int end = (int)Math.log10(num);
for(int i = 0; i < end; i++)
System.out.printf("%d, ", get(num, i));
System.out.println(get(num, end));
System.out.println();
return this;
}
public Questions question2() {
System.out.println("Question2:");
int rand = (int)(Math.random() * 1000) + 1;
int times = 0, price;
while(true) {
price = reader.nextInt();
times++;
if(price > rand)
System.out.println("高了");
else if(price < rand)
System.out.println("低了");
else {
System.out.printf("恭喜!!!你用了%d次就猜对了\n", times);
break;
}
}
System.out.println();
return this;
}
public Questions question3() {
System.out.println("Question3:");
System.out.print("游戏开始吗?");
String choice = reader.next();
int a = 0, x = 0, y = 0, z = 0, machine, person;
if(choice.equals("开始")) {
do {
machine = (int)(Math.random() * 2);
person = (int)(Math.random() * 2);
a++;
if(machine == person) {
System.out.println("平局");
z++;
} else if(machine > person) {
System.out.println("机器赢了");
y++;
} else {
System.out.println("人赢了");
x++;
}
System.out.print("要继续吗?");
choice = reader.next();
} while(choice.equals("继续"));
System.out.printf("总共是:%d次\n", a);
System.out.printf("人 赢:%d次\n", x);
System.out.printf("机器赢:%d次\n", y);
System.out.printf("平 局:%d次\n", z);
}
System.out.println();
return this;
}
public Questions question4() {
System.out.println("Question4:");
double height = 100, sum = 0, lastHeight;
for(int i = 0; i < 10; i++) {
sum += height;
sum += height /= 2;
}
System.out.printf("第10次落地并反弹到最高点,共经过%f m\n", sum);
System.out.printf("第10次反弹%f m\n", height);
System.out.println();
return this;
}
public static void main(String[] args) {
new Questions().question1().question2().question3().question4();
}
}
public class Questions {
Scanner reader = new Scanner(System.in);
public int get(int num, int index) {
if(num < 0 || index < 0 || index > (int)Math.log10(num))
return - 1;
int i = (int)Math.ceil(Math.pow(10, index));
return num / i % 10;
}
public Questions question1() {
System.out.println("Question1:");
int num = reader.nextInt();
int end = (int)Math.log10(num);
for(int i = 0; i < end; i++)
System.out.printf("%d, ", get(num, i));
System.out.println(get(num, end));
System.out.println();
return this;
}
public Questions question2() {
System.out.println("Question2:");
int rand = (int)(Math.random() * 1000) + 1;
int times = 0, price;
while(true) {
price = reader.nextInt();
times++;
if(price > rand)
System.out.println("高了");
else if(price < rand)
System.out.println("低了");
else {
System.out.printf("恭喜!!!你用了%d次就猜对了\n", times);
break;
}
}
System.out.println();
return this;
}
public Questions question3() {
System.out.println("Question3:");
System.out.print("游戏开始吗?");
String choice = reader.next();
int a = 0, x = 0, y = 0, z = 0, machine, person;
if(choice.equals("开始")) {
do {
machine = (int)(Math.random() * 2);
person = (int)(Math.random() * 2);
a++;
if(machine == person) {
System.out.println("平局");
z++;
} else if(machine > person) {
System.out.println("机器赢了");
y++;
} else {
System.out.println("人赢了");
x++;
}
System.out.print("要继续吗?");
choice = reader.next();
} while(choice.equals("继续"));
System.out.printf("总共是:%d次\n", a);
System.out.printf("人 赢:%d次\n", x);
System.out.printf("机器赢:%d次\n", y);
System.out.printf("平 局:%d次\n", z);
}
System.out.println();
return this;
}
public Questions question4() {
System.out.println("Question4:");
double height = 100, sum = 0, lastHeight;
for(int i = 0; i < 10; i++) {
sum += height;
sum += height /= 2;
}
System.out.printf("第10次落地并反弹到最高点,共经过%f m\n", sum);
System.out.printf("第10次反弹%f m\n", height);
System.out.println();
return this;
}
public static void main(String[] args) {
new Questions().question1().question2().question3().question4();
}
}
----------------解决方案--------------------------------------------------------
LZ摆明了不想自己编,来求源代码来了
----------------解决方案--------------------------------------------------------
{ai}
----------------解决方案--------------------------------------------------------
那里能学啊JAVA啊。。。
----------------解决方案--------------------------------------------------------
好长
----------------解决方案--------------------------------------------------------
好长的代码啊 ,有点看不懂,可能是我还没学到哪里来吧。
----------------解决方案--------------------------------------------------------
这算长吗?一个小的操作系统可能有几十万行,大的可能有几百万行,这段代码才94行。。。
----------------解决方案--------------------------------------------------------