- 三个和尚升级版
三个和尚的身高需经过测量得出,用程序实现获取这三个和尚的最高身高。
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
//创建对象<br /> Scanner sc = new Scanner(System._in_);
//接受数据,键盘输入三个身高<br /> int height1 = sc.nextInt();<br /> int height2 = sc.nextInt();<br /> int height3 = sc.nextInt();
//比较大小,选出最大的身高<br /> int a = height1 > height2 ? height1 : height2;<br /> int maxHeight = a > height3 ? a : height3;
//输出最高身高<br /> System._out_.println("maxHeight:"+ maxHeight);<br /> }<br />}
- 猜数字
import java.util.Random;
import java.util.Scanner;
public class Test {
public static void main(String[]args) {
Random r = new Random();
int number = r.nextInt(100)+1;
while(true){<br /> Scanner sc = new Scanner(System._in_);<br /> int guessnumber = sc.nextInt();
if (guessnumber < number){<br /> System._out_.println("猜小了");<br /> }else if(guessnumber >number){<br /> System._out_.println("猜大了");<br /> }else{<br /> System._out_.println("恭喜你猜对了");<br /> break;<br /> }<br /> }<br /> }<br /> }
- 输出水仙花数
public class Test {
public static void main(String[] args) {
for(int i =100; i<1000; i++){
int ge = i%10;
int shi = i/10%10;
int bai = i/100;
if(ge*ge*ge + shi*shi*shi + bai*bai*bai == i){<br /> System._out_.println(i);<br /> }<br /> }<br /> }<br />}
4.水仙花数共有几个
public class Test {
public static void main(String[] args) {
int count = 0;
for(int i =100; i<1000; i++){
int ge = i%10;
int shi = i/10%10;
int bai = i/100;
if(ge*ge*ge + shi*shi*shi + bai*bai*bai == i){<br /> count++;<br /> }<br /> }<br /> System._out_.println("水仙花数共有"+count + "个");<br /> }<br />}
5.while循环语句折纸到珠峰
int zf =8844430;
double paper = 0.1;
int count = 0;
while(paper < zf){
paper *= 2;
count ++;
}
System.out.println(“需要折叠 :”+ count +”次”);