最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

奇怪的 Java 语法

网站源码admin104浏览0评论
本文介绍了奇怪的 Java 语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

当我遇到这个问题时,我正在做一个练习计算机科学 UIL 测试表:

I was doing a practice Computer Science UIL test form when I came across this problem:

下面的输出是什么?

int a = 5;
int b = 7;
int c = 10;
c = b+++-c--+--a;
System.out.println(a + " " + b + " " + c);

我记下了由于语法错误没有输出"的答案,但我弄错了.真正的答案是 4 8 1!(我自己测试过)

I put down the answer "No output due to syntax error" but I got it wrong. The real answer was 4 8 1! (I tested it out myself)

有人可以向我解释第 4 行是如何工作的吗?
谢谢

Can someone please explain to me how line 4 works?
Thanks

推荐答案

我加了一些括号:

int a = 5;
int b = 7;
int c = 10;
c = (b++) + (-(c--)) + (--a);
System.out.println(a + " " + b + " " + c);

b++:使用 b 后的 b = b + 1

b++ : b = b + 1 after b is used

c-- :使用 c 后的 c = c - 1

c-- : c = c - 1 after c is used

--a :a = a - 1 在使用 a 之前

--a : a = a - 1 before a is used

这篇关于奇怪的 Java 语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

发布评论

评论列表(0)

  1. 暂无评论