public class E { public static void main(String args[]){ int m = 100; System.out.println(m+"100");//【代码】 } l
时间: 2023-06-13 15:05:14 浏览: 106
在代码中,需要使用加号来将字符串和变量连接起来。修改后的代码如下:
```
public class E {
public static void main(String args[]) {
int m = 100;
System.out.println(m + "100");
}
}
```
输出结果为:`100100`。
相关问题
class Test{ public static void main(String[] args){ System.out.println(i); int i =10; } }
这段代码会报错,因为变量 `i` 在使用之前被引用。在 `System.out.println(i)` 的位置,编译器会提示找不到符号 `i` 的错误。在 Java 中,变量必须先声明后使用。如果你想在 `System.out.println(i)` 中打印变量 `i` 的值,需要将其声明在使用之前。以下是修改后的代码:
```java
class Test {
public static void main(String[] args) {
int i = 10;
System.out.println(i);
}
}
```
这样修改后,代码就可以成功输出变量 `i` 的值 10。
public class StrDemo{ public static void main(String[] args){ String str1=”We are Students”; int n1=str1.length; int n2=str1.indexof(“students”) boolean b=str1.contains(“good”) System.out.println(n1); System.out.println(n2); System.out.println(b); }
这段代码有一些语法错误,应该修改为:
```
public class StrDemo {
public static void main(String[] args) {
String str1 = "We are Students";
int n1 = str1.length();
int n2 = str1.indexOf("students");
boolean b = str1.contains("good");
System.out.println(n1);
System.out.println(n2);
System.out.println(b);
}
}
```
这段代码的作用是定义一个 `StrDemo` 类,其中包含一个 `main` 方法。在 `main` 方法中,定义了一个字符串变量 `str1`,并获取了它的长度和包含子串 `"students"` 的位置。同时,使用 `contains` 方法判断字符串中是否包含子串 `"good"`,并将结果输出到控制台。