// This program gives Lucas numbers. import java.util.Scanner; public class Lucas { public static void main ( String args []) { int input = -1; Scanner i = new Scanner ( System.in ); while (input <0 || input >76) { System.out.print("Which Lucas number would you like? "); input = i.nextInt(); } System.out.printf("Lucas #%d is %.0f\n", input, getLucas(input)); } /** * This method gets user input to calculate Lucas numbers * * @param input The desired lucas number requested by user * @return The calculated lucas number as a double */ public static double getLucas( int input ) { double lucas; double num1 = 2; double num2 = 1; double num3 = 0; int count = 0; if (input == 0) lucas = 2; else if (input == 1) lucas = 1; else { while ( count < input-1 ) { num3 = num1 + num2; num1 = num2; num2 = num3; count++; } lucas = num3; } return lucas; } }