98.下列程序段正确的是 ( )。 A. String A="firstJava"; B. String A="firstJava"; A-="Java"; A+="Java"; C. Integer J=new Integer(27); D. Integer J=new Integer(27); J-=7; J--;
时间: 2024-02-14 20:20:43 浏览: 27
正确的是 C. `Integer J=new Integer(27);`。
A 选项是正确的 Java 字符串定义方式,但是没有其他操作。
B 选项是错误的,因为字符串是不可变的,不能使用 `-=` 操作符。
D 选项也是错误的,因为 `Integer` 类型是不可变的,不能使用 `-=` 操作符,也不能使用递减操作符 `--`。
所以只有 C 选项是正确的,它定义了一个 `Integer` 类型的对象 `J`,并赋值为 27。
相关问题
Java求sn=a aa aaa ... 的值
这是一个数学问题,与Java编程无关。但是,我可以给你提供一个Java代码示例,来计算这个数列的值:
```java
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
String s = "a";
BigInteger sum = BigInteger.valueOf(0);
for (int i = 0; i < 1000; i++) {
s += "a";
BigInteger num = new BigInteger(s);
sum = sum.add(num);
}
System.out.println(sum);
}
}
```
这个程序使用了BigInteger类,可以处理大整数运算。它通过循环计算数列中的每一项,最后将它们加起来,得到了结果。
编写java程序计算 a=4c/b 的值
以下是一个Java程序,可以计算 a=4c/b 的值,其中c和b的值可以从命令行参数中获取:
```java
public class Calculation {
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("需要输入两个参数 c 和 b");
return;
}
int c = Integer.parseInt(args[0]);
int b = Integer.parseInt(args[1]);
double a = 0.0;
if (b != 0) {
a = 4.0 * c / b;
} else {
System.out.println("除数不能为零");
return;
}
System.out.println("a = " + a);
}
}
```
运行示例:
```
$ java Calculation 10 2
a = 20.0
$ java Calculation 10 0
除数不能为零
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)