1.在控制台输出购物清单
![](https://i-blog.csdnimg.cn/direct/c58b9acceffc4a06a31b736e53a1a4f3.png)
![](https://i-blog.csdnimg.cn/direct/6ac8b2011ac74a01a449b647c48098a8.png)
public class Text {
public static void main(String[] args) {
System.out.println("\t\t 购物清单");
System.out.println("商品名称\t 购买数量\t 商品单价\t金额");
System.out.println("鳄鱼夹克\t 1 \t 1900\t 1900");
System.out.println("ipodMP4\t 2 \t 400\t 800");
}
}
2.在控制台输出购物系统登录菜单和系统主菜单
![](https://i-blog.csdnimg.cn/direct/645147063477417d820109fa68276c4f.png)
![](https://i-blog.csdnimg.cn/direct/3f1a1abd738c452e8760022f4c4b77ad.png)
public class Test1 {
public static void main(String[] args) {
System.out.println("\t\t\t欢迎使用我行我素购物系统1.0版");
System.out.println("\t\t\t\t 1.登录系统");
System.out.println("\t\t\t\t 2.退出");
System.out.println("********************************************");
System.out.println("请选择,输入数字:");
Scanner input = new Scanner(System.in);
int select = input.nextInt();
switch (select){
//选择数字1进入主菜单
case 1:
System.out.println("\t\t\t欢迎使用我行我素购物系统1.0版");
System.out.println("********************************************");
System.out.println("\t\t\t\t 1.用户信息管理");
System.out.println("\t\t\t\t 2.购物结算");
System.out.println("\t\t\t\t 3.真情回顾");
System.out.println("\t\t\t\t 4.注销");
System.out.println("********************************************");
break;
case 2:
System.out.println("bye~");
break;
}
}
}
3.计算圆的面积
public class Volume {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入圆的半径:");
double radius = input.nextDouble();
double volume = (4/3) * Math.PI * Math.pow(radius,3);
System.out.printf("球的体积是:%.2f",volume);
}
}
4.通过输入秒数判断从0:0:0开始,现在处于什么时间
public class Time {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入秒数:");
int totalSeconds = input.nextInt();
int hours = totalSeconds / 3600;
int minutes = totalSeconds % 3600 / 60;
int seconds = totalSeconds % 60;
System.out.print("当前时间是:" + hours + ":" + minutes + ":" + seconds);
}
}
5.华氏温度与摄氏温度之间的转换
public class Temperature {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入华氏温度:");
double fahrenheit = input.nextDouble();
double celsius = (fahrenheit - 32) * (5.0 / 9.0);
System.out.printf("摄氏温度是:%.2f℃",celsius);
}
}
6.输入三门课成绩,并计算总分和平均分
![](https://i-blog.csdnimg.cn/direct/a9e4d47e7d4d42f2b8755f670bb0ab15.png)
public class Score {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入java的成绩:");
double javaScore = input.nextDouble();
System.out.print("请输入Oracle的成绩:");
double oracleScore = input.nextDouble();
System.out.print("请输入HTML的成绩:");
double htmlScore = input.nextDouble();
double sum = javaScore + oracleScore + htmlScore;
System.out.println("总分是:"+sum);
double avg = sum / 3;
System.out.print("平均分是:"+avg);
}
}
7.输入父母身高,推测孩子身高
public class Height {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.print("请输入父亲的身高(厘米):");
int father = input.nextInt();
System.out.print("请输入母亲的身高(厘米):");
int mather = input.nextInt();
int son = (int) ((father + mather)*1.08 / 2);
int dauther = (int)((father*0.923 + mather) / 2);
System.out.println("儿子的身高是:"+son+"CM");
System.out.println("女儿的身高是:"+dauther+"CM");
}
}