+ 1

/playground/program. java: error: incompatible types:possible lossy conversation from double to int int actual_amt=(amt *10)/100

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amt = scanner.nextInt(); for(int i=0;i<=3;i++){     int actual_amt=(amt * 10)/100; amt=amt-actual_amt; }System.out.println(amt); } }

27th Dec 2021, 5:58 PM
AYESHA SULTANA
4 Respuestas
+ 2
Remove front space or rewrite line no:14 int actual_amt = .... This code has no that type of error. If you take amt as double type then you will get that error. Then use cast to int Like int actual_amt = (int) (amt*10/100) ;
27th Dec 2021, 6:13 PM
Jayakrishna 🇮🇳
+ 2
Yes. No convertion Your code above posted, have no incompatible type error. I said it in my last reply. All are int type you are using so there integer arithmetic only happens.. It has only, invalid character error (it may occurs if code is copied from any net sources..) If there any precision loss of data then use farmula like int actual_amt= (int) (amt*10/100.0) ; Or simply (int) (amt*0.1) ; //here first all converted to double type then result is calculated, so result is in double type , you need to cast to sourse type int to not loss data. Hope it clears... ?
28th Dec 2021, 9:31 AM
Jayakrishna 🇮🇳
+ 1
tq u.. but internalized first only as int amt= scanner.nextInt (); then how amt became double type 🤔
28th Dec 2021, 4:31 AM
AYESHA SULTANA
+ 1
tq u~
29th Dec 2021, 12:15 AM
AYESHA SULTANA