一、超市特价商品采购
运行过程及其结果:
import java.util.Scanner;
public class yicpaocjidan {//创建类
public static void main(String[] args) {//主方法
System.out.print("请输入鲜鸡蛋的重量: "); //输出鲜鸡蛋的重量
Scanner input = new Scanner(System.in);
int egg = input.nextInt();//定义
int i = egg-7;//定义
if (egg <= 7) {//使用if条件
System.out.println(egg*3.98);//输出信息
}else {//使用if条件
try {//try...catch代码块
int ar = Integer.parseInt("异常提示:这份鲜鸡蛋的重量是"+egg+"斤你超重了"+i+"斤");
}catch(Exception e) {//try...catch代码块
System.out.println("异常提示:这份鲜鸡蛋的重量是"+egg+"斤你超重了"+"斤");//输出信息
}
}
}
}
二、统计学校人数
运行过程及其结果: