Swap Function
Swap two values using a helper function.
package DSA.Functions;
import java.util.Scanner;
public class swapFunc { // swap and multiply public static int swaping(int a, int b) { int temp = a; a = b; b = temp; System.out.println(a); System.out.println(b); return 0; }
public static int mul(int a, int b) { return a * b; }
public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { System.out.println("Enter 2 Numbers"); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println("Enter Task: * or swap"); String ac = sc.next(); switch (ac) { case "*": int mul = mul(a, b); System.out.println(mul); break; case "swap": swaping(a, b); default: break; } } catch (Exception e) { System.out.println(e); } }}