0

Java - How to iterate an amount 3 times subtracting 10% each loop

Loops

9th Aug 2022, 8:00 AM
Linux Penguin
10 Réponses
0
Can i use * 0.1 instead of divide
9th Aug 2022, 8:11 AM
Linux Penguin
0
Variable is int, scanner input
9th Aug 2022, 8:15 AM
Linux Penguin
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(int i = 0; i < 3; i++) { amount -= amount/10; System.out.println(amount-(i)); } } } // Can you help correct me
9th Aug 2022, 8:25 AM
Linux Penguin
0
My results are a fraction off. How is this
9th Aug 2022, 8:25 AM
Linux Penguin
0
Thanks how do i print the previous two months aswell just gives me the final month
9th Aug 2022, 8:57 AM
Linux Penguin
0
Linux Penguin If you want to print all 3 months deduction , here is the way : import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(int i = 0; i < 3; i++) { amount -= amount/10; System.out.println(amount-(i)); } } } Just place the code lines in the block of for loop {} to get executed
11th Aug 2022, 4:05 AM
Swaraj Soubhagya Khandai
Swaraj Soubhagya Khandai - avatar
0
Ok i done the toCharArray method i had to make print outside the loop
11th Aug 2022, 7:53 AM
Linux Penguin