本帖最后由 無聊 于 2019-1-7 21:51 编辑 import java.util.Scanner;
public class hello
{
public static void main(String[] args){
int inputValue = 0;
String strR = ""; //信号信号可辨度字符串
String strS = ""; //信号强度字符串
String strOutput = "";
int iR = 0; //信号可辨度
int iS = 0; //信号强度
//获得用户输入
Scanner input = new Scanner(System.in);
System.out.print("Please input value: ");
inputValue = input.nextInt();
input.close();
//判断输入是否有效
if (inputValue < 11 || inputValue > 59)
{
System.out.println("input value error!");
return;
}
//根据"整数的十位部分表示可辨度,个位部分表示强度"从输入的数字拆分出R和S
iS = inputValue % 10;
System.out.println("input value iS = " + iS);
iR = inputValue / 10;
System.out.println("input value iR = " + iR);
//根据拆分出来的iS获得信号强度字符串
switch (iS) {
case 1:
strS = "Faint signals, barely perceptible";
break;
case 2:
strS = "Very weak signals";
break;
case 3:
strS = "Weak signals";
break;
case 4:
strS = "Fair signals";
break;
case 5:
strS = "Fairly good signals";
break;
case 6:
strS = "Good signals";
break;
case 7:
strS = "Moderately strong signals";
break;
case 8:
strS = "Strong signals";
break;
case 9:
strS = "Extremely strong signals";
break;
default:
break;
}
//根据拆分出来的iR获得信号可辨度字符串
switch (iR) {
case 1:
strR = "Unreadable";
break;
case 2:
strR = "Barely readable, occasional words distinguishable";
break;
case 3:
strR = "Readable with considerable difficulty";
break;
case 4:
strR = "Readable with practically no difficulty";
break;
case 5:
strR = "Perfectly readable";
break;
default:
break;
}
//根据要求拼接信号强度字符串和信号可辨度字符串
strOutput = strS + "," + " " + strR.toLowerCase();
System.out.println(strOutput);
}
}
|