qq_慕无忌3268011
2018-12-25 22:18
public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
three=one+two;
System.out.println("three=one+two==>"+(one+two));
System.out.println("three+=one==>"+(three+one));
System.out.println("three-=one==>"+(three+one-one));
System.out.println("three*=one==>"+(three*one));
System.out.println("three/=one==>"+(three*one/one));
System.out.println("three%=one==>"+three%one);
你注意一下题目的要求和输出结果,题目要求的输入结果:
题目的要求是three这个变量每次都要被重新赋值,并作为下一次的输入项。但是你这里的three只是作为一个常量参加运算,因此跟题目不符合。
正确的写法应该是:
Public class HelloWorld{ public static void main(String[] args) { int one = 10 ; int two = 20 ; int three = 0 ; three = one + two; System.out.println("three = one + two ==> " + three); three += one; System.out.println("three += one ==> " + three); three -= one; System.out.println("three -= one ==> " + three); three *= one; System.out.println("three *= one ==> " + three); three /= one; System.out.println("three /= one ==> " + three); three %= one; System.out.println("three %= one ==> " + three); } }
Java入门第一季(IDEA工具)升级版
1165172 学习 · 17581 问题
相似问题