Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么操作员不给出不同的结果,而使用=给出正确的答案 static int count=0; 公共静态void main(字符串[]args){ 扫描仪sc=新的扫描仪(System.in); 计数=0; int n=sc.nextInt(); int arr[][]=新的int[n][n]; 对于(int i=0;i_Java_Operators - Fatal编程技术网

Java 为什么操作员不给出不同的结果,而使用=给出正确的答案 static int count=0; 公共静态void main(字符串[]args){ 扫描仪sc=新的扫描仪(System.in); 计数=0; int n=sc.nextInt(); int arr[][]=新的int[n][n]; 对于(int i=0;i

Java 为什么操作员不给出不同的结果,而使用=给出正确的答案 static int count=0; 公共静态void main(字符串[]args){ 扫描仪sc=新的扫描仪(System.in); 计数=0; int n=sc.nextInt(); int arr[][]=新的int[n][n]; 对于(int i=0;i,java,operators,Java,Operators,如果我将yes=true替换为yes=!yes,则输出将不同。请帮助,似乎无法理解。 函数行出现的问题部分是: 如果我们在第i行,那么我们必须一次处理每一列 从0到n−对于任何第j列,将A[i][j]与 索引为j的列中存在的所有元素的最小值 以及从索引i到n的行−一, 问题是该语句可以多次执行。在yes=true的情况下,结果总是yes变为true。但是如果yes=!yes,当你说yes>时,yes将在true和false之间切换=真的,它永远都是真的。但是当你说,yes=!yes它会在真与假之

如果我将
yes=true
替换为
yes=!yes
,则输出将不同。请帮助,似乎无法理解。 函数行出现的问题部分是:

如果我们在第i行,那么我们必须一次处理每一列 从0到n−对于任何第j列,将A[i][j]与 索引为j的列中存在的所有元素的最小值 以及从索引i到n的行−一,


问题是该语句可以多次执行。在
yes=true
的情况下,结果总是
yes
变为
true
。但是如果
yes=!yes
,当你说
yes>时,
yes
将在
true
false
之间切换=真的
,它永远都是真的。但是当你说,
yes=!yes
它会在真与假之间来回翻转

 static int count = 0;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    count = 0;
    int n = sc.nextInt();
    int arr[][] = new int[n][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        arr[i][j] = sc.nextInt();
      }
    }
    for (int i = 0; i < n ; i++) {
      row(arr, n, i);
      column(arr, n, i);
    }
    System.out.println(count);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        System.out.print(arr[i][j] + " ");
      }
    }
  }

  static void row(int arr[][], int n, int row) {
    int x, y, min, yHold = 0;

    for (x = 0; x < n; x++) {
      boolean yes = false;
      min = arr[row][x];

      for (y = row; y < n; y++) {
        if (arr[y][x] < min) {
          min = arr[y][x];
          yHold = y;
          yes = true;
        }
      }
      if (yes) {
        int temp = arr[row][x];
        arr[row][x] = min;
        arr[yHold][x] = temp;
        count++;
      }
    }

如果执行两次
yes=!yes
,会发生什么情况?是的,我现在明白了。显然我的测试用例是这样的,以至于要求的数字大部分时间都出现在奇数位置,这就是为什么我在这个问题上陷入了困境。谢谢大家的帮助。
boolean yes = true;
for (int i = i < 10; i++) {
 System.out.println(yes);   
 yes =! yes;
}
true
false
true
false
true
false
true
false
true
false