WILLIAM S.

asked • 02/08/21

Divide input integers

Write a program using integers userNum and divNum as input, and output userNum divided by divNum three times.

Ex: If the input is:

2000 2

the output is:

1000 500 250

Note: In Java, integer division discards fractions. Ex: 6 / 4 is 1 (the 0.5 is discarded).


Sebastion H.

public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int userNum; int divNum; userNum = scnr.nextInt(); divNum = scnr.nextInt(); System.out.print((userNum/divNum) + " " ); System.out.print(((userNum/divNum)/divNum) + " " ); System.out.println((((userNum/divNum)/divNum)/divNum) + " " );
Report

09/08/21

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.