集册 Java实例教程 从控制台读取的除整数,还可以得到余数

从控制台读取的除整数,还可以得到余数

欢马劈雪     最近更新时间:2020-01-02 10:19:05

418
从控制台读取的除整数,还可以得到余数

import java.util.Scanner;
/*n o w j a v a . c o m - 时  代  Java 提供*/

public class MarblesApp

{

  static Scanner sc = new Scanner(System.in);


  public static void main(String[] args)

  {

    // declarations

    int numberOfMarbles;

    int numberOfChildren;

    int marblesPerChild;

    int marblesLeftOver;


    // get the input data

    numberOfMarbles = 50;

    System.out.print("Number of children: ");

    numberOfChildren = 7;
/* 来自 时 代 J a v a - nowjava.com*/

    // calculate the results

    marblesPerChild = numberOfMarbles / numberOfChildren;

    marblesLeftOver = numberOfMarbles % numberOfChildren;


    // print the results

    System.out.println("Give each child " +

      
展开阅读全文