利用入口方法String[ ]args,两种代码编写两个数商和余数的程序#String[ ] args

一:第一种方法 


package cn;

import java.util.Scanner;

/**
 * <p>Project: jce - suan</p>
 * <p>Powered by Cyy On 2023-07-06 15:02:44</p>
 * <p>描述:<p>
 *
 * @author Cyy [210585265@qq.com]
 * @version 1.0
 * @since 17
 */
public class suan {
    public static void main(String[] args) {
        //自动获取键盘输入内容
        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.print("请输入两个整数:");
            int a = sc.nextInt();
            int b = sc.nextInt();
            double a1 =a;
            double b2=b;
            if (a % b == 0) {
                System.out.printf("%d/%d=%d%n",a,b,a/b);
            } else {
                System.out.printf("%d/%d=%d ... %d%n",a,b,a/b,a%b);
            }
        }

    }
}

说明

 Scanner sc =new Scanner(System.in);

这是调用Scanner类方法,此方法会自动获取用户在命令下键盘输入的两个数值

sc.nextInt();将获得的参数赋值给其他变量使用

二:第二种方法 


package cn.cn;

/**
 * <p>Project: jce - suans</p>
 * <p>Powered by Cyy On 2023-07-06 20:30:52</p>
 * <p>描述:<p>
 *
 * @author Cyy [210585265@qq.com]
 * @version 1.0
 * @since 17
 */
public class suans {
    public static void main(String[] args) {
        int a = Integer.parseInt(args[0]);
        int b = Integer.parseInt(args[1]);
        if (a % b == 0) {
            System.out.printf("%d/%d=%d%n", a, b, a / b);
        } else {
            System.out.printf("%d/%d=%d ... %d%n", a, b, a / b, a % b);
        }

    }
}

输出操作步骤:

1.右上角点击

2.在画红色箭头的地方输入两个数字,中间用空格隔开 

 3.结果图

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值