Alternate Method: Write a java program to find the lcm .Given input in the form of day interval of dinner. Find the day on which they both will lunch together / dinner together.


Program
import java.util.Scanner; public class Lunchlcm { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter the day interval of Tony"); int n1=sc.nextInt(); System.out.println("Enter the day interval of Potts"); int n2=sc.nextInt(); if(n1<=0 && n2<=0) { System.out.println("Given interval is not valid"); return; } int a=n1; int b=n2; while(n2>0) { if (n1 > n2) { n1 = n1 - n2; } else { n2 = n2 - n1; } } int gcd = n1; int lcm = (a * b) / gcd; System.out.println("Tony and Potts will have lunch together on " + lcm + " day"); } }
Input
Output