Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

Define class BasicCalculator | Hello World | Programming

Define class BasicCalculator

 

turned on black Android smartphone

 

 

The class Hello.java accepts two integers X and Y as the input. The class Hello.java must Subtraction Multiplication, Integer Division, Float Division and Modulo) on the given two intege

The class Hello.java is given below.

import java.util.Scanner;

import com.skillrack.BasicCalculator;

public class Hello {

public static void main(String args[]) {

Sekarz Scanner sc = new Scanner(System.in); int X sc.nextInt ();

int Y sc.nextInt();

System.out.println (BasicCalculator.addition (X, Y));

System.out.println(BasicCalculator, subtraction(X, Y));

System.out.println(Basictalculator multiplication(X, Y));

System.out.println(BasicCalculator, integerDivision (X, Y));

System.out.printf("%.3f\n", BasicCalculator floatDivision (X, Y));

System.out.println(BasicCalculator.modulo(x, y));

}

}


Your task is to define the class BasicCalculator in the package com.skillrack so that the program runs succe

Example Input/Output 1:

Input: 20 8

Output

28

12

160

2

2.500

4

Explanation:
20 + 8 = 28
20 - 8 = 12
20 * 8 = 160
20 / 8 = 2 (Integer division)
20 / 8 = 2.5 (Float division)
20 % 8 = 4

Example Input/Output 2:
Input:
7 9

Output:
16
-2
63
0
0.778
7

 

SOLUTION

JAVA PROGRAM :

package com.skillrack;
import java.util.*;

public class BasicCalculator{
    public static int addition(int X,int Y){
        return X+Y;
    }
    public static int subtraction(int X,int Y){
        return X-Y;
    }
    public static int multiplication(int X,int Y){
        return X*Y;
    }
    public static int integerDivision(int X,int Y){
        return X/Y;
    }
    public static double floatDivision(int X,int Y){
        return X/(Y*1.0);
    }
    public static int modulo(int X,int Y){
        return X%Y;
    }
}

Post a Comment

Previous Post Next Post