examples[1]

# examples[1] - Michael Taylor import java.util.Scanner...

This preview shows pages 1–3. Sign up to view the full content.

Michael Taylor import java.util.Scanner; public class taylor { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //create object input Scanner input = new Scanner(System. in ); //get the first number System. out .print( "Enter first integer: " ); int num1 = input.nextInt(); //get the second number System. out .print( "Enter second integer: " ); int num2 = input.nextInt(); //display the output System. out .println( "The greatest common divisor for " + num1 + " " + " and " + num2 + " is " + gCommonDivisor (num1, num2)); } // method definition public static int gCommonDivisor( int num1, int num2) { //declare local variables int gcd = 1; int k = 2; //check to find common divisor while { if gcd = k; k++; //increment the value of k by 1 } return gcd; //return the value } } Enter first integer: 8 Enter second integer: 64 The greatest common divisor for 8 and 64 is 8 public class conversion {

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Michael Taylor /** * @param args */ public static void main(String[] args) { System. out .println( "Miles\t\tKilometers\t|\tKilometers\tMiles" ); System. out .println( "-----------------------------------------" ); double mile = 1; double kilometer = 20; for ( int i = 1; i <= 10; mile++, kilometer+=5, i++) { System. out .println(mile + "\t\t" + mileToKilometer (mile) + "\t|\ t" + kilometer + "\t\t" + kilometerToMile (kilometer)); } } /* Converts from miles to kilokilometers */ static double mileToKilometer( double mile){ return mile * (1 / 1.609); } /* Converts form kilokilometers to mile */ static double kilometerToMile( double kilometer){ return 1.609 * kilometer; } } 6.0 3.7290242386575514 | 45.0 72.405 7.0 4.35052827843381 | 50.0 80.45 8.0 4.9720323182100685
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

examples[1] - Michael Taylor import java.util.Scanner...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online