WILLIAM S.
asked 02/08/21Divide 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).
More
1 Expert Answer
Inactive Tutor answered 03/03/21
Tutor
New to Wyzant
You can use a simple for loop to do this:
int dividend = userNum;
for( int i=0; i<3; i++){
dividend = dividend / divNum;
System.out.print(dividend + " ");
}
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.
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) + " " );09/08/21