How is 15/4 =3? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How is 15/4 =3?

22nd Mar 2016, 12:05 PM
Krishna Prasad
Krishna Prasad - avatar
11 Answers
+ 2
because 15/4=3.75 but data type is int so only integer part of 3.75 (i.e 3)is displayed neglecting decimal part. if we use float or double then we would have got 3.75
12th Jul 2016, 4:00 PM
Aditya Vartak
Aditya Vartak - avatar
+ 1
its variable type is int which hold only whole numbers so it records only the 3 and the rest is omitted
27th Mar 2016, 8:46 PM
Aric
Aric - avatar
+ 1
The answer depends on the variable and data type you assign to that number. int strictly avoids floating point values (values after decimal.point) so the answer will be just 3. For float and double the answer will be different.
30th Jun 2016, 12:12 PM
Based Hafeez
Based Hafeez - avatar
0
15/4 = 3.75 but if u will assign it's value in int variable then it will only consider 3 neglate the floating point value
22nd Jun 2016, 3:57 PM
gandhiyash
0
change data type from int to double... u will get full answer
23rd Jun 2016, 8:50 PM
Zellu Rakib
Zellu Rakib - avatar
0
cause ur using the initialization of the number as an int which means whole number, you can use double here preferably to get the number in a decimal form or float as well, good luck
27th Jun 2016, 3:48 AM
moe mufti
moe mufti - avatar
0
4 goes 3 times into 15 and remainder comes 3. that's it. thankx
30th Jun 2016, 11:03 AM
Deepak Kumar
Deepak Kumar - avatar
0
it is so cuz.... if you will use int a=15;b=4;c=a/b; then you get 3 as a solution. but if you use float c=a/b; then you get the right answer. it is so because int data type only stores the integer values and float stores the integer as well as decimal values also.
18th Aug 2016, 4:44 PM
Suraj Vishwakarma
Suraj Vishwakarma - avatar
0
Java or C initializes the result into integer if the user doesn't specifies it. for the 15/4 problem, if double a = 15/4 was given, it would give you, 3.75. but since you didn't mention, the data type, java compiler took it as int
4th Sep 2016, 9:39 AM
Anuttam Adhwaryu
Anuttam Adhwaryu - avatar
- 3
convert the result to Integer Integer. parseInt(qoutient);
24th Jun 2016, 3:02 PM
Drako Gemini
Drako Gemini - avatar
- 6
when u divide these two numbers then it's reminder is 3
23rd Jun 2016, 1:51 PM
sonali kaur