hurry_君君
2016-01-01 11:44
package com.waiting;
public class Test {
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
three=one+two;
three+=one;
three-=one;
three*=one;
three/=one;
System.out.println("three=one+two==>"+three);
System.out.println("three+=one==>"+three);
System.out.println("three-=one==>"+three);
System.out.println("three*=one==>"+three);
System.out.println("three/=one==>"+three);
System.out.println("three%=one==>"+three);
请问 有人帮我解答下吗?这个代码是不是应该这样写?结果怎么全都是最后一个数 30 30 30 3 0.。。。。啥意思啊
你好,这么写:
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); } }
你的问题是把所有的运行语句执行后,最后输出的,肯定结果都一样,应该执行一条输出一条,不然后会覆盖,
望楼主采纳!
只输出最后的结果,如果想把每一步的结果都输出,那么要在每一步后面都有个sysout
肯定是30,只输出最后一个计算结果
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);
Java入门第一季(IDEA工具)升级版
1167377 学习 · 18748 问题
相似问题