Java练习题(三)--信号报告

题目内容:无线电台的RS制信号报告是由三两个部分组成的:

R(Readability) 信号可辨度即清晰度.

S(Strength)    信号强度即大小.

其中R位于报告第一位,共分5级,用1—5数字表示.

1---Unreadable

2---Barely readable, occasional words distinguishable

3---Readable with considerable difficulty

4---Readable with practically no difficulty

5---Perfectly readable

报告第二位是S,共分九个级别,用1—9中的一位数字表示

1---Faint signals, barely perceptible

2---Very weak signals

3---Weak signals

4---Fair signals

5---Fairly good signals

6---Good signals

7---Moderately strong signals

8---Strong signals

9---Extremely strong signals

现在,你的程序要读入一个信号报告的数字,然后输出对应的含义。如读到59,则输出:Extremely strong signals, perfectly readable.

输入格式:一个整数,信号报告。整数的十位部分表示可辨度,个位部分表示强度。输入的整数范围是[11,59]内有效的数字,这个范围外的数字不可能出现在测试数据中。

输出格式:一句话,表示这个信号报告的意义。按照题目中的文字,先输出表示强度的文字,跟上逗号和空格,然后是表示可辨度的文字,跟上句号。注意可辨度的句子的第一个字母是小写的。注意这里的标点符号都是英文的。

输入样例:33

输出样例:Weak signals, readable with considerable difficulty.

思路:因为选择太多,用if-else的话工作量太大,所以就想到用switch-case,因为输入的是两位数,所以就想到把两位数分开,想要得到十位部分就用除法(RS/10)得到十位部分,想要的得到个位部分就取模(RS%10)。因为输入的整数范围是[11,59]内有效的数字,所以RS>=11&&RS<=59&&RS%10!=0(个位不能有0)。

package hello;

import java.util.Scanner;

public class Hello {

     public static void main(String[] args) {

           Scanner in= new Scanner(System.in);

           int RS=in.nextInt();

           if(RS>=11&&RS<=59&&RS%10!=0)

           {

                String ir=null,is=null;

                switch (RS/10)

                {

                     case 1:

                           ir="unreadable";

                           break;

                     case 2:

                           ir="barely readable, occasional words distinguishable";

                           break;

                     case 3:

                           ir="readable with considerable difficulty";

                           break;

                     case 4:

                           ir="readable with practically no difficulty";

                           break;

                     case 5:

                           ir="perfectly readable";

                           break;

                     default:

                           break;

                }

                switch(RS%10)

                {

                case 1:

                     is="Faint signals, barely perceptible";

                     break;

                case 2:

                     is="Very weak signals";

                     break;

                case 3:

                     is="Weak signals";

                     break;

                case 4:

                     is="Fair signals";

                     break;

                case 5:

                     is="Fairly good signals";

                     break;

                case 6:

                     is="Good signals";

                     break;

                case 7:

                     is="Moderately strong signals";

                     break;

                case 8:

                     is="Strong signals";

                     break;

                case 9:

                     is="Extremely strong signals";

                     break;

                }

                System.out.println(is+","+ir+".");

           }

     }

}

其他练习题:

Java练习题(一)--温度转换

Java练习题(二)--时间换算

你可能感兴趣的:(Java练习题(三)--信号报告)