0
why the code is not a solution of a modulo 2 project in java language
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //введите код сюда int x = 3 ; do { amount = amount / 100 * 90 ; x--; } while(x != 0); System.out.println(amount); } }
6 Respuestas
+ 3
So, you can declare the "temp" variable for it. Why doesn't your code solves the task? I think thats because Java compiler automatically convert the "float" to "int" but in wrong way. So your code have to look like:
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
//введите код сюда
float rez = 0;
int x = 3 ;
do {
rez = (float)amount / 100 * 90 ;
amount = (int)rez;
x--;
} while(x > 0);
System.out.println(amount);
}
}
+ 2
everything works great with three months as well
0
What's actual project you are talking about? Cuz there is no such task in second modulo of Java course
0
You borrow money from a friend and you need to calculate how much you owe him in 3 months. Every month you will return 10% of the debt to him. Create a program that uses the amount owed as input, calculates and outputs the remaining amount after 3 months. Example input: 20000 Example output: 10628
0
Here i added the "rez" variable with "float" datatype. Each iteration i do all operations and assign it to "rez" as float and then assign "rez" value to "amount" but as an integer
0
thanks for the help. I will be more attentive