一行,一个整数(0~30),表示KiKi挂的科目累计的学分。
一行,根据输入的挂科学分,输出相应学习情况(Danger++,Danger,Good)。
14
Danger++
9
Danger
1
Good
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
int score = sc.nextInt();
//按从小到大的条件判断可以少写一些条件
if (score<4){
System.out.println("Good");
}else if (score<10){
System.out.println("Danger");
}else {
System.out.println("Danger++");
}
}
}
} import java.util.Scanner;
/**
* @Title: 挂科危险
* @Remark: KiKi想知道这学期他的学习情况,BoBo老师告诉他这学期挂的科目累计的学分,根据所挂学分,判断KiKi学习情况,10分以上:很危险(Danger++),4~9分:危险(Danger),0~3:Good。
* 输入描述:
* 一行,一个整数(0~30),表示KiKi挂的科目累计的学分。
* 输出描述:
* 一行,根据输入的挂科学分,输出相应学习情况(Danger++,Danger,Good)。
* @Author: ijunfu
* @Version: 1.0.0
* @Date: 2022-03-20
*/
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int score = in.nextInt();
if(score >= 10) {
System.out.println("Danger++");
} else if(9 >= score && score >= 4) {
System.out.println("Danger");
} else {
System.out.println("Good");
}
in.close();
}
}
#include<stdio.h>
int main(void){
int score;
scanf("%d", &score);
if(score <= 3)
printf("Good\n"); // 0~3 输出Good
else if(score <= 9)
printf("Danger\n"); // 4-9 输出Danger
else if(score >= 10)
printf("Danger++\n"); // 大于等于10 输出Danger++
else
printf("Error\n"); // 其它值,输出Error
return 0;
} 增加写代码的熟练度
# include<bits/stdc++.h>
using namespace std;
int main()
{
int score;
cin >> score;
if(score>=0 and score <=3) cout << "Good\n";
else if(score <=9) cout << "Danger\n";
else if(score >=10) cout << "Danger++\n";
return 0;
} while(num = readline()) {
if(num >= 10){
console.log("Danger++")
} else if (num >= 4 && num <= 9) {
console.log("Danger")
} else {
console.log("Good")
}
} 解法二:switch...case分支 var n = parseInt(readline());
var r = '';
switch(true){
case n <= 30 && n >= 10:
r = 'Danger++';
break;
case n <= 9 && n >= 4:
r = 'Danger';
break;
case n <= 3 && n >= 0:
r = 'Good';
break;
default:
break;
}
console.log(r); score=int(input("请输入所挂学分")) if score >= 10: print("Danger++") elif score >=4 and score <=9 : print("Danger") elif score >=0 and score <=3: print("Good")
#include <stdio.h>
#include <math.h>
int main()
{
int grade;//定义整形变量->用于描述所挂学分
scanf("%d",&grade);//输入所挂学分
if(grade<=3)//判断
{
printf("Good");
}
else if(grade<=9)
{
printf("Danger");
}
else
{
printf("Danger++");
}
return 0;
}
import java.util.Scanner;
public class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int s;
while(sc.hasNextInt()){
s = sc.nextInt();
if(s >= 10)
System.out.println("Danger++");
else if(s >= 4 && s <= 9)
System.out.println("Danger");
else if(s >= 0 && s<=3)
System.out.println("Good");
}
}
}