Click here to Skip to main content
15,887,585 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Here is my just example code:

package javanew;
Java
public class JavaNew
{
    public static void main(String args[])
    {
        int a,b;
        double c;
        a=11;
        b=2;
        c=a/b;
        System.out.println(c);
    }
}

Output:
5.0


Now if I change the int into double then output is 5.5. so if I want to get input value from user in integer and display result in double, what is the way for it?
Posted
Updated 23-Dec-15 20:06pm
v2
Comments
Sergey Alexandrovich Kryukov 24-Dec-15 0:35am    
"Display result in double" is not clear at all. What is that supposed to mean? You already mentioned the "ways"...
—SA
[no name] 24-Dec-15 0:37am    
As a newbie you should realise these simple questions have been answered many times. You would be helping yourself greatly by learning to use Google. Here: http://stackoverflow.com/questions/3144610/java-integer-division-how-do-you-produce-a-double

1 solution

You can do casting :

c = (double)a / b;


I don't know java but you can try this if it works or not.

Good luck.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900