What does the following class output? class output { public void work() { int totalCost = 6; int items = 12; System.out.println("cost per item: "+ totalCost/items); }}
Advertisements
प्रश्न
What does the following class output?
class output
{
public void work()
{
int totalCost = 6;
int items = 12;
System.out.println("cost per item: "+ totalCost/items);
}}पर्याय
cost per item: .5
cost per item: 0
cost per item: 1
cost per item: +6/12
MCQ
Advertisements
उत्तर
cost per item: 0
Explanation:
Both totalCost and items are integers. In Java, integer division (6 / 12) gives 0 because the fractional part is discarded.
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
