why the code is not a solution of a modulo 2 project in java language | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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); } }

21st Mar 2021, 7:45 AM
Denis
Denis - avatar
6 Answers
+ 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); } }
21st Mar 2021, 8:35 AM
Nazeekk
Nazeekk - avatar
+ 2
everything works great with three months as well
21st Mar 2021, 9:02 AM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
0
What's actual project you are talking about? Cuz there is no such task in second modulo of Java course
21st Mar 2021, 8:13 AM
Nazeekk
Nazeekk - avatar
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
21st Mar 2021, 8:16 AM
Denis
Denis - avatar
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
21st Mar 2021, 8:37 AM
Nazeekk
Nazeekk - avatar
0
thanks for the help. I will be more attentive
21st Mar 2021, 8:40 AM
Denis
Denis - avatar