Java零基础程序阅读一

初南电脑学习 2024-02-21 08:31:32
1、找出下列程序中的问题: public OutputHello {// 程序的主方法为“静态方法”,须用关键字“static”修饰public void main(String[] args) {System.out.println("H H EEEEEEE L L OOOOO");System.out.println("H H E L L O O");System.out.println("HHHHHHH EEEEEEE L L O O ");System.out.println("H H E L L O O");System.out.println("H H EEEEEEE LLLLLLL LLLLLLL OOOOO");}}2、找出下列程序中的问题: public CelsiusToFahrenheit {public static void main(String[] args) {int celsius = 37;System.out.println("要转换的摄氏度 = " + celsius);// 9/5的结果是int型,9.0/5的结果是double型double fahrenheit = 9/5 * celsius + 32;int intfahrenheit = fahrenheit;System.out.println("37摄氏度 = " + fahrenheit + "华氏度(未转换成int型)");System.out.println("37摄氏度 = " + intfahrenheit + "华氏度(转换成int型)");}}3、找出下列程序中的问题: public GoodsVan {public static void main(String[] args) {int vanWidth = 2;int vanLength = 4;double boxWidth = 1.5;double boxLength = 1.5;// 箱子数的数据类型为整型,且载货区宽度与箱子宽度的商、载货区长度与箱子长度的商的数据类型都应该被转换为int型double boxNumber = (vanWidth/boxWidth) * (vanLength/boxLength);System.out.println("载货区一层可以放" + boxNumber + "箱子!");}}4、找出下列程序中的问题: import java.util.Scanner;public SLLogin {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("请输入用户名:");String userName = sc.next();System.out.print("请输入密码:");String password = sc.next();// 使用equals()方法比较字符串是否相等,例如"A".equals("B")if (userName == "mingri" && password == "mrsoft") {System.out.println("登录成功!");} else {System.out.println("登录失败!请重新输入……");}sc.close();}}5、找出下列程序的问题 import java.util.Scanner;public Seasons {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("请输入某个月份(1~12):");int month = sc.nextInt();// 缺少判断条件:输入的月份是否小于1或大于12switch (month) {case 3:case 4:case 5:System.out.println(month + "月正值春季");break;case 6:case 7:case 8:System.out.println(month + "月正值夏季");break;case 9:case 10:case 11:System.out.println(month + "月正值秋季");break;case 12:case 1:case 2:System.out.println(month + "月正值冬季");break;}sc.close();}}
0 阅读:0

初南电脑学习

简介:感谢大家的关注