Dividing Integers you read from console, also get the remainder - Java Language Basics

Java examples for Language Basics:Operator

Description

Dividing Integers you read from console, also get the remainder

Demo Code

import java.util.Scanner;

public class MarblesApp
{
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args)
  {//from www .ja  v a  2  s.c  om
    // declarations
    int numberOfMarbles;
    int numberOfChildren;
    int marblesPerChild;
    int marblesLeftOver;

    // get the input data
    numberOfMarbles = 50;
    System.out.print("Number of children: ");
    numberOfChildren = 7;

    // calculate the results
    marblesPerChild = numberOfMarbles / numberOfChildren;
    marblesLeftOver = numberOfMarbles % numberOfChildren;

    // print the results
    System.out.println("Give each child " +
        marblesPerChild + " marbles.");
    System.out.println("You will have " +
        marblesLeftOver + " marbles left over.");
  }

}

Related Tutorials