0
Can anyone tell me the mistake here please?
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); double amount = scanner.nextInt(); int resultado = (int) amount; double mes = 1; while( amount > 0 && mes < 7 && resultado > 0) { amount = amount * 0.9; ++mes; resultado = (int) amount; } System.out.println(resultado); } }
2 Answers
+ 2
What is it your trying to achieve? seems to work ok if input is none decimal?
+ 1
nextInt() accept only Integer values. So you enter decimal value then raise error.
Instead of these 2 lines,
double amount = scanner.nextInt();
int resultado = (int) amount;
you can write in single line like
int resultado= scanner.nextInt();
And next, resultado += 0.9;