0
Java - How to iterate an amount 3 times subtracting 10% each loop
Loops
10 Answers
0
Can i use * 0.1 instead of divide
0
Variable is int, scanner input
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
0
My results are a fraction off. How is this
0
Thanks how do i print the previous two months aswell just gives me the final month
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
0
Ok i done the toCharArray method i had to make print outside the loop