This Java program prompts the user to enter two integer numbers, and then determines whether their sum or difference is equal to 15 or if either of the numbers is 15. The program then prints the result to the console.
Note that the program assumes that the input numbers are integers. If you want to allow for non-integer input or if you want to modify the conditions for determining the result, you would need to modify the calculate method accordingly.
import java.util.*; public class Sum_Difference { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter First Integer Number : "); int fn = input.nextInt(); System.out.print("Enter Second Integer Number : "); int sn = input.nextInt(); System.out.print("Result is : "+calculate(fn, sn)); } public static boolean calculate(int fn, int sn) { if(fn == 15 || sn == 15) return true; return ((fn + sn) == 15 || Math.abs(fn - sn) == 15); } }
Enter First Integer Number : 52 Enter Second Integer Number : 37 Result is : true
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions