• Register
0 votes
31 views
 I am a noob in java, I have a task to cast a double to an int in java and I wrote a program to solve this:
 public static void main(String args[]) 
    { 
  
        double data = 3452.345; 
 
        int value = data; 

        System.out.println(value); 
    } 

But it gives an error:

  Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types: possible lossy conversion from double to int
	at javastackoverflow.NewClass1.main(NewClass1.java:14)
C:\Users\Hp\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 1 second)

What is the problem in my code?

10 7 2
6,060 points

Please log in or register to answer this question.

1 Answer

0 votes
You have to parse a double (data) into Int data you can code like that :
  
    public static void main(String args[]) 
    { 
  
        double data = 3452.345; 
 
        int value = (int)data; 

        System.out.println(value); 
    } 

 

11 6 4
34,950 points

Related questions

0 votes
0 answers 4 views
4 views
Problem: I used Google to try to find a solution on the web of the above question, But I got no useful hints. Can I get Pointer information about my problem with this?
asked Mar 21 shamimkhan 15.1k points
0 votes
1 answer 1 view
1 view
Problem: Why I got this error: how to cast double to int in c#? idea on what I need to fix this. I am new in programming. Thanks in advance.
asked Mar 15 jasimchaudary 1.5k points
0 votes
1 answer 2 views
2 views
Problem If i want to casting a integer value to double in c++, how it is possible? Someone can help me.
asked Apr 8 Subhendu 4.5k points
0 votes
1 answer 3 views
3 views
Problem: I am in desperate need of help and any suggestions will be grately appreciated,"c# cast double to int."
asked Apr 8 Humaira ahmed 15.2k points
1 vote
1 answer 6 views
6 views
Problem : Getting error in sending arraylist of object from adapter to other activity. I wanna send my arraylist from onBindViewHolder method of Adapter to another activity but its is showing null exception error on the Cast Class in writetoParcel Method. Getting Error ... Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null object reference How to send arraylist properly?
asked Mar 31 Shovo210 14k points
0 votes
1 answer 20 views
20 views
Problem: Let’s say that the double variable x holds the value 3.6987 and needs to be converted to an int. There are two ways that this can be done: Which type of methods use for converting double type into int type? Given a Double real number, the task is to convert it into Integer in Java. Examples: Input: double = 3452.234 Output: 3452 Input: double = 98.23 Output: 98
asked Dec 3, 2020 Mashhoodch 13k points
0 votes
1 answer 5 views
5 views
Problem: I will request someone to answer my question Please, I have searched on the web but I got no useful information for this, now I am in difficulty continuing my learning
asked Mar 22 sadi1982 36.3k points
1 vote
1 answer 2 views
2 views
Problem: Why I got the error : the activity must be exported or contain an intent-filter. you can cast a character value to an int, or an int to char.
asked Mar 7 MUHAMMAD MUNEEB 83k points
0 votes
1 answer 1 view
1 view
Problem: I will request someone to answer my question Please, I have searched on the web but I got no useful information for this, now I am in difficulty continuing my learning
asked Mar 21 Samiur1 38.4k points
0 votes
1 answer 2 views
2 views
Problem: can someone please help for this problem? how to parse a string to an int in java
asked Apr 1 Rohit kr 16.2k points