Eclipse 如何声明整数';s值在system.out.println中

Eclipse 如何声明整数';s值在system.out.println中,eclipse,if-statement,Eclipse,If Statement,如何将a和b的随机值插入system.out.println,以便在控制台窗口中显示随机数 public class MoreIfStmts { /* Chase Pittman * This program compares two variables and tells which one is greater or if they're equal. */ public static void main(String[] args) { i

如何将a和b的随机值插入system.out.println,以便在控制台窗口中显示随机数

public class MoreIfStmts {

    /* Chase Pittman
    * This program compares two variables and tells which one is greater or if they're equal.
    */
    public static void main(String[] args) {
        int q=0;
        while (q < 10) {
            q=q+1;
    int a=0;
    int b=0;
                a=(int) (Math.random() * 10);
                b=(int) (Math.random() * 10);
        if (a > b)
        {
            System.out.println ("Blue is better than red.");
        } // This is the end of the then clause.
            else
            {
            if (a < b)
            {
                    System.out.println ("Red is better than blue.");
                } // This is the end of the if clause.

                    else
                    if (a == b)
                    {
                        System.out.println ("Blue is as good as red.");
                } // This is the end of the second else clause.
            } // This is the end of the first else clause.
        } // This is the end of while statement.
    } // This is the end of main.
} // This is the end of class MoreIfStmts.
公共类更多信息{
/*蔡斯·皮特曼
*这个程序比较两个变量,并告诉哪一个更大或者它们是否相等。
*/
公共静态void main(字符串[]args){
int q=0;
而(q<10){
q=q+1;
int a=0;
int b=0;
a=(int)(Math.random()*10);
b=(int)(Math.random()*10);
如果(a>b)
{
System.out.println(“蓝色比红色好”);
}//这是then子句的结尾。
其他的
{
if(a
System.out.println(“红色比蓝色好。”+“a=“+a+”b=“+b”)

您也可以使用格式化输出:

System.out.printf("Blue is better than red. a = %d, b = %d\n", a, b);

所有右大括号上的注释使代码更难阅读,而不是更容易阅读。如果您将光标放在相应的大括号上,Eclipse将为您高亮显示该大括号。如果您希望在外部插入值,则可以向“main”方法提供参数。这就是“args”参数的用途。