0

I need help with this program. Please help

import java.util.Scanner; public class Main { public static void main(String[] args) { int ans = 0; int cona; int conb; int fg = 0; System.out.println("Hi! I find the LCM of 2 numbers!"); System.out.println("What is the first number?"); Scanner MyVar = new Scanner(System.in); int FN = MyVar.nextInt(); System.out.println("What is the second number?"); Scanner MyVat = new Scanner(System.in); int SN = MyVat.nextInt(); int[] faray = new int[10001]; int[] saray = new int[10001]; for (int x = 0; x <= 10000; x++) { cona = FN * x; conb = SN * x; faray[x] = cona; saray[x] = conb; } for (int a:faray) { if (fg == 0) { for (int b:saray) { if (a == b) { ans = a; fg++; break; } } } } System.out.println("The LCM of " + FN + " and " + SN + " is " + ans); } }

29th May 2020, 5:30 PM
Sudhir Krisna
2 Answers
+ 2
Please send the link of your code instead... So that we can test it
29th May 2020, 5:38 PM
Namit Jain
Namit Jain - avatar
+ 1
avoid to compare 0==0 at begin of arrays eg for (int b:saray) { if (a == b && a!=0) { for Sololearn do not use two Scanner(System.in)
30th May 2020, 12:17 AM
zemiak