+ 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); } }
4 Antworten
+ 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) ;
+ 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... ?
+ 1
tq u..
but internalized first only as
int amt= scanner.nextInt ();
then how amt became double type 🤔
+ 1
tq u~