在Java中<-是什么? [英] What is <-- in Java?

查看:215
本文介绍了在Java中<-是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在下面的代码段中遇到了.它输出到4 3 2 1

I came across below snippet. It outputs to 4 3 2 1

我从没遇到过Java中的<--.

I never came across <-- in Java.

<--是将var1的值设为var2的运算符吗?

Is <-- an operator that makes the value of var1 to var2?

public class Test {

    public static void main(String[] args) {

        int var1 = 5, var2 = 0;
        while (var2 <-- var1) {
            System.out.print(" " + var1);
        }
    }
}

推荐答案

<--不是新的Java运算符(即使看起来像这样),但是有2种常规运算符:<--

<-- is not a new Java operator (even though it may look like it), but there are 2 normal operators: < and --

while (var2 <-- var1)while(var2 < (--var1))相同,可以将其翻译为普通英语:

while (var2 <-- var1) is the same as while(var2 < (--var1)), which can be translated to plain english as:

  1. 减少var1变量(--var是前缀减少,即在条件验证之前减少变量)
  2. 验证条件var2 < var1
  1. decrement the var1 variable ( --var is a prefix decrementation, ie. decrement the variable before condition validation)
  2. Validate the condition var2 < var1

这篇关于在Java中&lt;-是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆