answersLogoWhite

0


Best Answer

// The "LCMTest" class.

import hsa.*;

public class LCMTestDanyalM

{

// Place your lowestCommonMultiple code here

public static int lowestCommonMultiple (int firstNumber, int secondNumber)

{

/// int product = 1;

// int limit = firstNumber * secondNumber;

for (int count = 1 ; ; count++)

{

if (count % firstNumber 0)

{

return count;

}

}

}

// Do not modify the code below

public static void main (String [] args)

{

Console c = new Console ();

final int NO_OF_TEST_CASES = 1000000; // maximum of 1000000

int [] first = new int [NO_OF_TEST_CASES];

int [] second = new int [NO_OF_TEST_CASES];

int [] LCM = new int [NO_OF_TEST_CASES];

c.println ("Loading the data...");

TextInputFile inFile = new TextInputFile ("lcmdata.txt");

int index = 0;

while (!inFile.eof () && index < first.length)

{

first [index] = inFile.readInt ();

second [index] = inFile.readInt ();

LCM [index] = inFile.readInt ();

index++;

}

inFile.close ();

// Testing the correctness and speed

c.println ("Start Timing");

long startTime = System.currentTimeMillis ();

for (int nextTest = 0 ; nextTest < first.length ; nextTest++)

{

int studentLCM = lowestCommonMultiple (first [nextTest], second [nextTest]);

if (studentLCM != LCM [nextTest])

{

c.println ("Incorrect: For " + first [nextTest] +

" and " + second [nextTest] + " you got "

+ studentLCM + " for the lowest common mulitple,"

+ "\nbut the answer should be: "

+ LCM [nextTest]);

break;

}

}

long endTime = System.currentTimeMillis ();

c.print ("Total Time: ");

c.println ((endTime - startTime), 20);

c.println ("Program Complete");

} // main method

} // Perfect class

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a Java program that finds the least common multiple of three integers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Basic Math

What is 20 percent of 380?

380/100 finds 1 percent. * 20 = 76


What does the QBASIC automatically capitalize for you?

EXAMPLE 1 The QBASIC program will, automatically, *capitalize* any reserved 'keyword' which it finds once you've already gone and typed in a line of code; and, then, at the end of that code line, do finally press the [RETURN/ENTER] key...to confirm what you've just gone and typed in. A keyword might be say the PRINT command statement...so, if I were to type inside of the QBASIC editor the following line of code... print 1+1 ...then, the moment I press the [RETURN/ENTER] key when I get to the end of that line...the QBASIC interpreter program will, automatically, change the 'lower case' word: print...to become all UPPERCASE, instead; QBASIC Editor will display the previous line of code I typed in as being... PRINT 1+1 ...thus, I am able to tell immediately that PRINT is a special reserved 'keyword'/or, command statement which the QBASIC program, quite clearly, recognizes and understands. This also helps me the programmer to know if I actually typed in that 'keyword' either correctly/or, incorrectly; if wrong...and, the program did NOT automatically capitalize it...; then, I know I must have either accidentally 'misspelled' the keyword/or, must otherwise have done something to go get it wrong...?! EXAMPLE 2 If I were to type in to the QBASIC Editor program the following line of code using all 'lower case' letters... x=10: if x=10 then print "ten" else print "NOT ten" ...and, then, when I've reached the end of that line of code, press [RETURN/ENTER] key to confirm my code entry; the QBASIC interpreter program will, automatically, respond by capitalizing any reseved 'keywords' that it finds; then, QBASIC Editor displays the line of code I typed in as being... x=10 : IF x=10 THEN PRINT "ten" ELSE PRINT "NOT ten" Looking at this newly capitalized line...it tells me that... IF/THEN/ELSE/PRINT...are all QBASIC reserved 'keywords'. NOTE: Whatever is a string a text that is written in between double quote marks: ("") will be totally unaffected by such capitalizing; instead, text strings will be printed out, quite literally, 'as is'. FINAL NOTE There are far too many QBASIC 'keywords' for me to go and list here; possibly, a couple hundred...! QBASIC has many 'keywords' that it uses; if you wish to see what ALL of these keywords are; then, from inside of the QBASIC Editor program itself...do a combination key press of: [SHIFT] + [F1]...and, there you will see the Help file...that shows each 'keyword' you can use to write QBASIC programs with; as well as, offering a clear explanation/it shows 'example codes' demonstrating exactly how each of these 'keywords' should be used; just do 'copy &amp; paste'/then, RUN the program to follow these examples along.


What does anticipating mean?

It means expected, or awaited. To 'anticipate' something is to 'expect' it or 'predict' it in the future. For instance if someone throws you a ball you have to anticipate where it will be in order for you to catch it. Alternatively if you have done something naughty, you can anticipate that your mother will be cross when she finds out.


How can you find the LCM and HCF by using the factor tree?

The factor tree finds the prime factorizations The prime factorizations find the GCF and LCM.Example 30 and 42:3015,25,3,24221,27,3,22 x 3 x 5 = 302 x 3 x 7 = 42Select the common factors.2 x 3 = 6, the GCFCombine the factors, eliminating duplicates.2 x 3 x 5 x 7 = 210, the LCMCheck it.30 x 42 = 1260210 x 6 = 1260It checks.


What is the difference between a main idea question and a detail question?

The basic difference between the two types of questions is: A main idea question asks for the broad definition of the topic - For example, What is Harry Potter about? You would give a general answer that tells about the story. (Its about a boy who finds out that he is a wizard.) But a detail question would want an answer that contains more information - For example, Who is Harry Potter? You would give an answer telling us about the character, his personality, where he came from, who his parents were, etc. ( Harry Potter is a young boy that finds out he is a wizard after his parents have died and has been sent to live with his relatives.) Hope that helps.

Related questions

How do you find the greatest common multiple?

The greatest common multiple of any set of numbers is infinite. There really is no way that you can find the greatest common multiple because numbers never stop so there is really no way that you can solve that. This is the way of math.The greatest common multiple of any set of integers is infinite. No one ever finds it.


What is the linux program that finds and repair disk error?

fsck


Is there a program that finds a selected color and clicks on it?

Impossible sorry. :(


Definition of Multiplying by the least common denominator?

Ordinarily, one finds the least common denominator (LCD) of a set of common fractions in order to add or subtract the set of fractions. The LCD is the least common multiple (LCM) of the denominators of the set of fractions. Without knowing whatis to be multiplied by the LCD, and why, this question is ambiguous.


What are the release dates for The Jack Benny Program - 1950 Jack Finds a Double 15-23?

The Jack Benny Program - 1950 Jack Finds a Double 15-23 was released on: USA: 12 March 1965


What do you do when the boss finds multiple errors at work?

Say you're sorry and promise to do better.


Write a C program that takes a binary file as input and finds error check using different mechanisms?

write a c program that takes a binary file as input and finds error check using different mechanisms.


How do you compile and execute a java program which finds out the highest of any five numbers?

it will be destroyed.


What is the program that finds websites and Web pages?

A "web crawler", A "search engine", A "web browser.


What is driver manager?

Driver Manager is a program that scans and finds out what is missing in your computer such as a missing driver.


What does gasp and gay have in common?

When a person finds out that you are gay, sometimes they gasp.


How does a bearded dragon finds its food?

With its eyes, and nose and its common sense.