java编写程序实现学时转换为学分,16个学时为1个学分,学分最小是0.5,2退3进,7退8进
时间: 2023-10-31 22:05:18 浏览: 149
下面是一个Java程序,实现学时转换为学分:
```java
import java.util.Scanner;
public class StudyCreditConversion {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入学时:");
int studyHours = scanner.nextInt();
double credits = studyHours / 16.0;
if (credits < 0.5) {
credits = 0.5;
}
System.out.println("学分为:" + credits);
if (credits == 2) {
System.out.println("退2进3");
credits = 3;
} else if (credits == 7) {
System.out.println("退7进8");
credits = 8;
}
System.out.println("转换后的学分为:" + credits);
}
}
```
程序运行时,会提示输入学时,然后按照16个学时为1个学分的规则进行计算,如果计算出来的学分小于0.5,则将学分设置为0.5。接着,根据题目要求,如果学分为2,则将它转换为3,如果学分为7,则将它转换为8。最后输出转换后的学分。
阅读全文
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)