Java2-2命令换行用大括号

2019年2月11日20:41:12 发表评论 1,194 views
/**
 * Created by xabcd on 2019/2/11.
 */
public class TestJava2_2
{public static void main(String args[])
{
    int x;
    int y;
    for(x=1;x<3;x++)
    {
        System.out.println
        (x+"*"+x+"="+x*x);//命令不止一行时需要用大括号
    }
    for(y=2;y<5;y++)
        System.out.println(y);
}
}



结果:
1*1=1
2*2=4
2
3
4



main() 方法 为 程序 的 主 方法, 在 一个 Java 程序 中有 且 只能 有一个 main() 方法, 它是 程序 运行 的 开端。

public 代表 main() 公有 的 method; static 表示 main() 在 没有 创建 类 对象 的 情况下, 仍然 可以 被 运行; void 则 表示 main() 方法 没有 返回 值。 main 后面 括号() 中的 参数 String args[] 表示 运行 该 程序 时 所需 要的 参数, 这是 固定 的 用法,

 

 

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: