Compare commits
No commits in common. "0f8de1a0b91420ca6261a9470abb9f30d5ef22c8" and "e929828dc59284e2f433735d1576bd7889f9b7a0" have entirely different histories.
0f8de1a0b9
...
e929828dc5
2 changed files with 0 additions and 100 deletions
|
|
@ -1,43 +0,0 @@
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class compountInterest {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
// Compound interest calculator
|
|
||||||
|
|
||||||
Scanner scanner = new Scanner(System.in);
|
|
||||||
|
|
||||||
// Initialize variables
|
|
||||||
double principal;
|
|
||||||
double rate;
|
|
||||||
int timesCompounded;
|
|
||||||
int years;
|
|
||||||
double amount;
|
|
||||||
|
|
||||||
// get inputs
|
|
||||||
System.out.print("Enter the principal amount: ");
|
|
||||||
principal = Double.valueOf(scanner.nextLine());
|
|
||||||
|
|
||||||
System.out.print("Enter the interest rate (in %): ");
|
|
||||||
rate = Double.valueOf(scanner.nextLine()) / 100;
|
|
||||||
|
|
||||||
System.out.print("Enter the # of times compounded per year: ");
|
|
||||||
timesCompounded = Integer.valueOf(scanner.nextLine());
|
|
||||||
|
|
||||||
System.out.print("Enter the # of years: ");
|
|
||||||
years = Integer.valueOf(scanner.nextLine());
|
|
||||||
|
|
||||||
// Calculate the compound interest
|
|
||||||
amount = principal * Math.pow(1 + rate / timesCompounded, timesCompounded * years);
|
|
||||||
|
|
||||||
// Print out the results
|
|
||||||
System.out.printf("\nThe amount after %d years is: $ %.2f", years, amount);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
scanner.close();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
public class printF {
|
|
||||||
|
|
||||||
public static void main(String[] args){
|
|
||||||
String name = "Spongebob";
|
|
||||||
char firstletter = 'S';
|
|
||||||
int age = 30;
|
|
||||||
double height = 60.5;
|
|
||||||
boolean isEmployed = true;
|
|
||||||
|
|
||||||
System.out.printf("Hello %s\n", name); // %s → formats a String
|
|
||||||
|
|
||||||
System.out.printf("Your name starts with a %c\n", firstletter); // %c → formats a single character (char)
|
|
||||||
|
|
||||||
System.out.printf("You are %d years old\n", age); // %d → formats an integer (decimal number)
|
|
||||||
|
|
||||||
System.out.printf("You are %f inches tall\n", height); // %f → formats a floating-point number (double / float)
|
|
||||||
|
|
||||||
System.out.printf("Employed: %b\n", isEmployed); // %b → formats a boolean (true / false)
|
|
||||||
|
|
||||||
|
|
||||||
// You can include multiple format specifiers in one print statement.
|
|
||||||
System.out.printf("%s is %d years old. He is %f inches tall\n", name, age, height);
|
|
||||||
// IMPORTANT: The values MUST be in the same order as the format specifiers.
|
|
||||||
|
|
||||||
double price = 9.99;
|
|
||||||
double price2 = -19.99;
|
|
||||||
double price3 = 19999.99;
|
|
||||||
|
|
||||||
|
|
||||||
// You can add special characters to alter how floats are shown
|
|
||||||
// a point '.' followed by a number specifies how many decimal places are shown
|
|
||||||
// A '+' shows a positive sign before the number
|
|
||||||
// // ( means that negative numbers are shown enclosed in ()
|
|
||||||
// 'space' means display a minus if negative, and a space if positive
|
|
||||||
// a ',' will add a comma grouping separator to the thousandths place
|
|
||||||
System.out.printf("The price for one is $% .2f, for two is $% .2f, and for 100 is $%,.2f\n", price, price2, price3);
|
|
||||||
|
|
||||||
|
|
||||||
// width
|
|
||||||
|
|
||||||
int id1 = 1;
|
|
||||||
int id2 = 23;
|
|
||||||
int id3 = 456;
|
|
||||||
int id4 = 7890;
|
|
||||||
|
|
||||||
// 0 = zero padding
|
|
||||||
// number = right justified padding
|
|
||||||
// negative number = left justified padding
|
|
||||||
|
|
||||||
System.out.printf("%4d\n", id1);
|
|
||||||
System.out.printf("%4d\n", id2);
|
|
||||||
System.out.printf("%4d\n", id3);
|
|
||||||
System.out.printf("%4d\n", id4);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue