/ Assignment / assignment_25.java
assignment_25.java
1 /* 2 * Accept user input of 1 number and print the opposite value 3 * Constraints : 4 * 1. 1 <= input <= 2 5 * If input is 1, we should display 1 and if input is 2, we should display 1 6 * Do not use comparison operators 7 */ 8 9 import java.util.Scanner; 10 11 public class assignment_25 { 12 public static int approach1(int num) { 13 return 3 - num; 14 } 15 16 public static int approach2(int num) { 17 return 2 / num; 18 } 19 public static void main(String[] args) { 20 Scanner sc = new Scanner(System.in); 21 22 int input = sc.nextInt(); 23 System.out.println("Approach 1 output: "); 24 int approach1_op = approach1(input); 25 System.out.println(approach1_op); 26 27 System.out.println("Approach2 output: "); 28 int approach2_op = approach2(input); 29 System.out.println(approach2_op); 30 } 31 }