Can you please help me fix my code * You need to implement this * This function
ID: 3888068 • Letter: C
Question
Can you please help me fix my code
* You need to implement this
* This function takes two int parameters, and a PrintStream, and prints (to the given PrintStream) their sum, difference, product, quotient and remainder.
* Preferably, print a message before it, like "The sum of 3 and 5 is 8"
* @param number1
* @param number2
*/
// notice this is void, so you call it like: printAllOperatiions(1,2,System.out)
public static void printAllOperations(int number1, int number2, PrintStream out)
{
// TODO - you need to implement this
sum = number1 + number2;
product = number1 * number2;
difference = number1 - number2;
quotient = number1 / number2;
remainder= number1 % number2;
System.out.println("The sum of "+number1+" and "+number2+" is "+sum);
printAllOperations(1,2,System.out);
System.out.print("The difference of "+number1+" and "+number2+" is " +difference);
printAllOperations(10,5,System.out);
System.out.print("The product of "+number1+" and "+number2+" is " +product);
printAllOperations(9,9,System.out);
System.out.print("The quotient of "+number1+" and "+number2+" is " +quotient);
printAllOperations(12,12,System.out);
System.out.print("The remiander of "+number1+" and "+number2+" is " +remainder);
printAllOperations(5,10,System.out);
}
Explanation / Answer
Dear Student,
here i have corrected the given Java Code.
NOTE: The below program has been tested on and online compiler. This program will also work on other IDE's like Netbeans and Eclipse IDE.
------------------------------------------------------------------------------------------------------------------------------------------
Program:
------------------------------------------------------------------------------------------------------------------------------------------
//import the necessary packages
import java.io.*;
//public class
public class Array
{
//start of main
public static void main (String[] args)
{
//calling the function in the main class
printAllOperations(1,2,System.out);
printAllOperations(10,5,System.out);
printAllOperations(9,9,System.out);
printAllOperations(12,12,System.out);
printAllOperations(5,10,System.out);
}
public static void printAllOperations(int number1, int number2, PrintStream out)
{
// TODO - you need to implement this
int sum = number1 + number2;
int product = number1 * number2;
int difference = number1 - number2;
int quotient = number1 / number2;
int remainder= number1 % number2;
//printing the output
out.println("The sum of "+number1+" and "+number2+" is "+sum + " ");
out.print("The difference of"+number1+" and "+number2+" is " +difference + " ");
out.print("The product of"+number1+" and "+number2+" is " +product + " ");
out.print("The quotient of"+number1+" and "+number2+" is " +quotient+ " ");
out.print("The remiander of"+number1+" and "+number2+" is " +remainder + " ");
}
}
-------------------------------------------------------------------------------------------------------------------------------------------
Here i have attached the output of the program as a screen shot...
OUTPUT:
-------------------------------------------------------------------------------------------------------------------------------------------
The sum of 1 and 2 is 3
The difference of1 and 2 is -1
The product of1 and 2 is 2
The quotient of1 and 2 is 0
The remiander of1 and 2 is 1
The sum of 10 and 5 is 15
The difference of10 and 5 is 5
The product of10 and 5 is 50
The quotient of10 and 5 is 2
The remiander of10 and 5 is 0
The sum of 9 and 9 is 18
The difference of9 and 9 is 0
The product of9 and 9 is 81
The quotient of9 and 9 is 1
The remiander of9 and 9 is 0
The sum of 12 and 12 is 24
The difference of12 and 12 is 0
The product of12 and 12 is 144
The quotient of12 and 12 is 1
The remiander of12 and 12 is 0
The sum of 5 and 10 is 15
The difference of5 and 10 is -5
The product of5 and 10 is 50
The quotient of5 and 10 is 0
The remiander of5 and 10 is 5
------------------------------------------------------------------------------------------------------------------------------------------
Kindly Check and Verify Thanks...!!!