Mini Multiplication Table §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Multiplication Table
// caleb b
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a minimum number: ");
int a = scanner.nextInt();
System.out.println("Enter maximum number: ");
int b = scanner.nextInt();
System.out.println("Enter the multiplier: ");
float c = scanner.nextFloat();
DecimalFormat df = new DecimalFormat("#,###.##");
for (int i = a; i <= b; i++) {
System.out.println(i + " x " + c + " = " + df.format(i * c));
}
}
}
Certificates of Deposits §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// CD
// caleb b
Scanner scan = new Scanner(System.in);
System.out.println("Enter initial deposit ($): ");
double initialDeposit = scan.nextDouble();
System.out.println("Enter annual interest rate (%): ");
double annualInterestRate = scan.nextDouble();
System.out.println("Enter target balance ($): ");
double targetBalance = scan.nextDouble();
int years = 0;
double balance = initialDeposit;
while (balance < targetBalance) {
balance += balance * (annualInterestRate / 100);
years++;
}
System.out.println("It will take " + years + " years to reach the target balance.");
}
}
Collatz Conjecture §
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Colatz Conjecture
// caleb b
Scanner scan = new Scanner(System.in);
System.out.println("Enter the starting number: ");
int n = scan.nextInt();
int count = 0;
List<Integer> list = new ArrayList<Integer>();
while (n != 1) {
if (n % 2 == 0) {
n = n / 2;
count++;
} else {
n = (3 * n) + 1;
count++;
}
System.out.print(" " + n + ", ");
}
}
}
View Next Assignment