请问怎么把一个字符串存储到一个变量中啊?谢谢好心人
学习Java的第3天请问一个小问题 谢谢你抽空解答请问怎么把字符串储存再一个变量:比如字母C里面啊?
这是我要做的题目我想的是把每个case后面的语句储存再一个字母C里面,再把两次对应的结果相加。
但我不知道怎么表达。
题目内容:
无线电台的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.
输入格式:
一个整数,信号报告。整数的十位部分表示可辨度,个位部分表示强度。输入的整数范围是内有效的数字,这个范围外的数字不可能出现在测试数据中。
输出格式:
一句话,表示这个信号报告的意义。按照题目中的文字,先输出表示强度的文字,跟上逗号和空格,然后是表示可辨度的文字,跟上句号。注意可辨度的句子的第一个字母是小写的。注意这里的标点符号都是英文的。
我等级不高不能发图,这是我写的代码。
case1 下面的一行就是我要做的尝试把一个字符串赋值给C
谢谢!
import java.util.Scanner;
public class Helloword {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int type =in.nextInt();
String str = new String("Hello world");
string c =in.nextInt();
switch(type) {
case 1:
c=("Faint signals, barely perceptible");
System.out.println(c);
case 2:
System.out.println("Very weak signals");
case 3:
System.out.println("Weak signals");
case 4:
System.out.println("Fair signals");
case 5:
System.out.println("Fairly good signals");
case 6:
System.out.println("Good signals");
case 7:
System.out.println("Moderately strong signals");
case 8:
System.out.println("Strong signals");
case 9:
System.out.println("Extremely strong signals");
}
}
}{:9_221:} 多个字符串连接可以用+
String a = "hello ";
a = a + "world!"
这样输出a 就是 “hello world!” 本帖最后由 無聊 于 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);
}
}
页:
[1]