用到UI吗?
把每个雨滴当做对象,抽象出来一个雨滴的类,里面包含雨落下的方向,速度,和失效的条件(落到地上了)。
再建立一个包含所有雨滴的容器,UI展示是通过容器里面获得的雨点对象来展示。
这样,容器里面每多出一个雨点对象,页面上就多出一个雨点。用完的对象从容器里面拿出来就好
import java.util.Scannerpublic class Weather {
public static String getWeatherInChinese(char c) {
switch (c) {
case 'D':
return "干燥"
case 'M':
return "潮湿"
case 'H':
return "炎热"
case 'R':
return "下雨"
default:
return "输入错误,无法转换"
}
}
public static void main(String[] args) {
boolean tbd = true
do {
System.out.print("请输入天气情况的第一个英文字母:")
Scanner scanner = new Scanner(System.in)
String input = scanner.next().trim()
if (input.length() != 1) {
System.out.println("输入错误,无法转换!")
} else {
System.out.println(getWeatherInChinese(input.charAt(0)))
}
System.out.print("你想继续吗?(y/n)")
String sta = scanner.next()
tbd = sta.equals("y") ? true : false
} while (tbd)
System.out.println("退出系统!")
}
}
运行截图:
public class demo{public static void main(String [] args){
for(int i=0i<112/14i++)
{
for(int j=0j<112/14j++)
{
if(112-20*i-12*j==0&&i+j==112/14)
System.out.println("晴天为:"+i+"天"+"雨天为"+j+"天")
}
}
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)