public static void main(String[] args) { int i = 0; i = i++; System.out.println("i = " + i); }
时间: 2023-05-13 20:06:37 浏览: 141
这段代码是一个简单的Java程序,其中i = i;这一行没有实际作用,可以直接删除。正确的代码应该是:
public static void main(String[] args) {
int i = 0;
System.out.println("i = " + i);
}
相关问题
指出下列Java语句中的错误,并说明错误原因。 public class VVW{ static int i=10; public static void main(String args[]){ { int k=10; System. out. println("i="+i); System. out. println("k="+k); } System. out. println("i="+i); System. out. println(''k=''+k); 〕 〉
错误原因:第一行缺少分号,应该是public class VVW{;第7行缺少加号,应该是System.out.println("i="+i);;第8行使用了单引号,应该使用双引号,应该是System.out.println("k="+k);。
正确代码:
public class VVW{
static int i=10;
public static void main(String args[]){
{
int k=10;
System.out.println("i="+i);
System.out.println("k="+k);
}
System.out.println("i="+i);
System.out.println("k="+k);
}
}
public class Main { public static void main(String[] args) { int size = 5; for (int i = 0; i < size; i++) { for
(int j = 0; j < size; j ) { System.out.print("*"); } System.out.println(); } }}
The code above is incomplete and will not run as it is missing the increment statement for the loop variables i and j.
A corrected version of the code would be:
public class Main {
public static void main(String[] args) {
int size = 5;
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
This code will print a square made of asterisks with a size of 5x5.
阅读全文