मराठी

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
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 6: Variables and Expressions - EXERCISE [पृष्ठ १३३]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
पाठ 6 Variables and Expressions
EXERCISE | Q 50. | पृष्ठ १३३
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×