为什么式子一样 结果不一样!
import java.util.Scanner;// 1:无需package
// 2: 类名必须Main, 不可修改
public class test {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int row = scan.nextInt();
int col = scan.nextInt();
String input = scan.nextLine();
int [][]map = new int;
int [][]result = new int;
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
int a = scan.nextInt();
map = a;
}
}
int sum = 0;
//先把1变9
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
if(map == 1){
result = 9;
}
else{
// 注释1 sum=map+map+map+map+
// map+map+map+map+map;
// result=sum;
// 注释2 sum=map+map+map+map+
// map+map+map+map+map;
// result=sum;
}
}
}
for(int i = 1; i <= row; i++){
for(int j = 1; j <= col; j++){
System.out.print(result + " ");
}
System.out.println();
}
scan.close();
}
}
在注释的地方有两个代码 明明一模一样 但答案不一样
这是输入
3 4
0 1 0 0
1 0 1 0
0 0 1 0
这是正确输出
2 9 2 1
9 4 9 2
1 3 9 2
本帖最后由 isdkz 于 2023-3-25 20:54 编辑
两个式子不一样呀
仔细看:
// 注释1 sum=map[i]+map+map+map+
// map[i]+map[i]+map+map+map[i+1];
// result[i]=sum;
// 注释2 sum=map[i]+map+map+map+
// map]+map]+map+map+map[j+1];
// result]=sum; isdkz 发表于 2023-3-25 20:53
两个式子不一样呀
仔细看:
什么这么简单的题目我又慢了{:10_282:} 本帖最后由 sfqxx 于 2023-3-25 20:58 编辑
//sum=map+map+map+map+
//map+map+map+map+map[i+1];
//result=sum;
//sum=map+map+map+map+
//map+map+map+map+map[j+1];
//result=sum; isdkz 发表于 2023-3-25 20:53
两个式子不一样呀
仔细看:
感谢老哥啊{:5_101:}
页:
[1]