------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Autonomy.java :::::::::::::: class Autonomy { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter the mileage for this car (miles/gallon): "); double m = console.readDouble(); System.out.print("Please enter the amount of fuel (in gallons): "); double f = console.readDouble(); System.out.println("The autonomy of the car is: " + m * f + " miles."); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Converter.java :::::::::::::: class Converter { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter the temperature in degrees Fahrenheit: "); double f = console.readDouble(); System.out.println(f + " degrees Fahrenheit is equal to " + (f - 32) * 5 / 9 + " degrees Celsius."); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Distance.java :::::::::::::: class Distance { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter x_1: "); double x_1 = console.readDouble(); System.out.print("Please enter y_1: "); double y_1 = console.readDouble(); System.out.print("Please enter x_2: "); double x_2 = console.readDouble(); System.out.print("Please enter y_2: "); double y_2 = console.readDouble(); System.out.println("The distance between (" + x_1 + ", " + y_1 + ") and (" + x_2 + ", " + y_2 + ") is: " + Math.sqrt( (x_1 - x_2) * (x_1 - x_2) + (y_1 - y_2) * (y_1 - y_2))); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Extract.java :::::::::::::: class Extract { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter a string: "); String a = console.readLine(); System.out.print("Please enter the first integer: "); int i = console.readInt(); System.out.print("Please enter the second integer: "); int j = console.readInt(); System.out.println("The extracted string is: " + a.substring(i, j)); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Investment.java :::::::::::::: class Investment { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter the initial balance (in dollars): "); double amount = console.readDouble(); amount = amount + 0.05 * amount; System.out.println("After a year the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After two years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After three years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After four years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After five years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After six years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After seven years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After eight years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After nine years the balance becomes: " + amount); amount = amount + 0.05 * amount; System.out.println("After ten straight years the balance becomes: " + amount + " dollars."); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Max.java :::::::::::::: class Max { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter the first number: "); double a = console.readDouble(); System.out.print("Please enter the second number: "); double b = console.readDouble(); int max = (int)(Math.round((a + b) / 2 + Math.abs(a - b) / 2)); System.out.println(max + " is the largest of " + (int)a + " and " + (int)b); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Reverse.java :::::::::::::: class Reverse { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter a string of at most 10 characters: "); String b = console.readLine(); System.out.println("You have entered the string: " + b); String a = " " + b; System.out.println(b + " reversed is " + a.substring(a.length() - 1, a.length()) + a.substring(a.length() - 2, a.length() - 1) + a.substring(a.length() - 3, a.length() - 2) + a.substring(a.length() - 4, a.length() - 3) + a.substring(a.length() - 5, a.length() - 4) + a.substring(a.length() - 6, a.length() - 5) + a.substring(a.length() - 7, a.length() - 6) + a.substring(a.length() - 8, a.length() - 7) + a.substring(a.length() - 9, a.length() - 8) + a.substring(a.length() - 10, a.length() - 9)); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Sq.java :::::::::::::: class Sq { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter a positive number: "); double n = console.readDouble(); System.out.println("We're going to calculate successive approximations of the square root of " + n + " now."); double x = 1; System.out.println("The first approximation is " + x + ", \n... and " + x + " squared is: " + x * x); System.out.println("Now we calculate (" + x + " + " + n + " / " + x + ") / 2 for the second approximation"); x = (x + n / x) / 2; System.out.println("which is " + x + ", (and " + x + " squared is: " + x * x + ")" ); System.out.println("Now we calculate (" + x + " + " + n + " / " + x + ") / 2 for the third approximation"); x = (x + n / x) / 2; System.out.println("which is " + x + ", (and " + x + " squared is: " + x * x + ")" ); System.out.println("Now we calculate (" + x + " + " + n + " / " + x + ") / 2 for the fourth approximation"); x = (x + n / x) / 2; System.out.println("which is " + x + ", (and " + x + " squared is: " + x * x + ")" ); System.out.println("Now we calculate (" + x + " + " + n + " / " + x + ") / 2 for the fifth approximation"); x = (x + n / x) / 2; System.out.println("which is " + x + ", (and " + x + " squared is: " + x * x + ")" ); System.out.println("Now we calculate (" + x + " + " + n + " / " + x + ") / 2 for the sixth approximation"); x = (x + n / x) / 2; System.out.println("which is " + x + ", (and " + x + " squared is: " + x * x + ")" ); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: SquareRoot.java :::::::::::::: class SquareRoot { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter a positive number: "); double n = console.readDouble(); System.out.println("We're going to calculate successive approximations of the square root of " + n + " now."); double x = 1; System.out.println("The first approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The second approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The third approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The fourth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The fifth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The sixth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The seventh approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The eighth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The nineth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); x = (x + n / x) / 2; System.out.println("The tenth approximation is " + x + ", \n... and " + x + " squared is: " + x * x); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Swap.java :::::::::::::: class Swap { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter a string of characters (of any length): "); String input = console.readLine(); System.out.println("Here's the string after the swap: " + input.charAt(input.length() - 1) + input.substring(1, input.length() - 1) + input.charAt(0)); } } ------------------------------------------------------------------------------------------------------------------------- :::::::::::::: Triangle.java :::::::::::::: class Triangle { public static void main(String[] args) { ConsoleReader console = new ConsoleReader(System.in); System.out.print("Please enter the length of the first side: "); double a = console.readDouble(); System.out.print("Please enter the length of the second side: "); double b = console.readDouble(); System.out.print("Please enter the length of the third side: "); double c = console.readDouble(); double s = (a + b + c) / 2; System.out.println("The semiperimeter is: " + s); System.out.println("The area of the triangle is: " + Math.sqrt(s * (s - a) * (s - b) * (s - c))); } } -------------------------------------------------------------------------------------------------------------------------