Advertisement
CR7CR7

return

Oct 7th, 2022
913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public class ReturningMultipleValues {
  2.    static int[] calculate(int a, int b){
  3.       int[] result = new int[4];
  4.       result[0] = a + b;
  5.       result[1] = a - b;
  6.       result[2] = a * b;
  7.       result[3] = a / b;
  8.       return result;
  9.    }
  10.    public static void main(String args[]){
  11.       Scanner sc = new Scanner(System.in);
  12.       System.out.println("Enter the value of a: ");
  13.       int a = sc.nextInt();
  14.      
  15.       System.out.println("Enter the value of b: ");
  16.       int b = sc.nextInt();
  17.       int[] result = calculate(a, b);
  18.      
  19.       System.out.println("Result of addition: "+result[0]);
  20.       System.out.println("Result of subtraction: "+result[1]);
  21.       System.out.println("Result of multiplication: "+result[2]);
  22.       System.out.println("Result of division: "+result[3]);
  23.    }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement