java——int、args[]传参、标签、数字塔?、一个输入格式

1.当int型整数超出自己范围时,会从它的上界重新开始。

public class exp {
    public static void main(String[] args) {
        int i = 2147483647;
        ++i;
        System.out.println(i);        
    }    
}

输出:-2147483648

2.在eclipse里怎样给main()函数里的args[]参数赋值?

public class exp {
    public static void main(String[] args ) {
        char symbol;
        symbol = args[0].charAt(0);
        System.out.println(symbol);
    }
}

这段代码要读取args[]中的一个字符,在控制台中可以通过java exp abc 将参数abc传入程序中,

(如果控制台要输入多个参数,用空格分割)

在eclips中可以这样做:

点击Run Configurations

选择arguments

在program arguments里传入参数

点击apply

点击run

 

标签:

  只能定义在for(){}/do{}while()/while(){}这三种循环的开始位置;

  带标签的break的语句可以使程序从复合语句或循环体内退出到指定标签所标识的外层语句块末尾,继续执行后面的语句;

数字塔:

public class exp {
    public static void main(String[] args) {
        int n = 4;
        for(int i=1; i<=n; i++) {
            for(int j=1;j<=n-i; j++)
                System.out.print("  ");
            for(int j=1; j<=i; j++)
                System.out.print(" "+j);
            for(int j=i-1; j>0; j--)
                System.out.print(" "+j);
            System.out.println();
        }
    }
}

 一个输入格式:

for(int i=0; i<marks.length; i++) {
    System.out.println("marks["+i+"]"+marks[i]);
}
原文地址:https://www.cnblogs.com/gaoquanquan/p/9656568.html