Pythagorean Theorem §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// pythagoras
// caleb b
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.##");
System.out.print("Enter the length of the first side: ");
double a = input.nextDouble();
System.out.print("Enter the length of the second side: ");
double b = input.nextDouble();
double c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
System.out.println("The length of the hypotenuse is " + df.format(c));
}
}
Division Calculator with Rounding §
import java.text.DecimalFormat;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// division system with rounding
// caleb b
Scanner scanner = new Scanner(System.in);
System.out.println("Enter first number: ");
float one = scanner.nextFloat();
System.out.println("Enter second number: ");
float two = scanner.nextFloat();
DecimalFormat decimalFormat = new DecimalFormat("#.##");
System.out.println(decimalFormat.format(one / two));
System.out.println("Unrounded Value: " + one / two);
}
}
View Next Assignment