Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package lab3;
- import java.util.Scanner;
- public class lab3part1 {
- public static void main (String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.println(
- "\nFeet Meters | Meters Feet\n" +
- "----------------------------------------------");
- for (double feet = 1.0, meters = 20.0; feet <= 10.0; feet++, meters += 5)
- {
- System.out.printf("%4.1f ", feet);
- System.out.printf("%6.3f", footToMeter(feet));
- System.out.print(" | ");
- System.out.printf("%-11.1f", meters);
- System.out.printf("%7.3f\n", meterToFoot(meters));
- }
- }
- public static double footToMeter(double foot) {
- return 0.305 * foot;
- }
- public static double meterToFoot(double meter) {
- return 3.279 * meter;
- }
- }
- package lab3;
- import java.util.Scanner;
- public class lab3part2 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in); // Create a Scanner
- System.out.print("Enter the number of sides: ");
- int n = input.nextInt();
- System.out.print("Enter the side: ");
- double side = input.nextDouble();
- System.out.println("The area of the polygon is " + area(n, side));
- }
- public static double area(int n, double side) {
- return (n * Math.pow(side, 2) / (4 * Math.tan(Math.PI / n)));
- }
- }
- package lab3;
- import java.util.Scanner;
- import java.math.*;
- public class lab3part3 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- System.out.print("Enter an integer: ");
- String n = input.nextLine();
- System.out.println("Factorial of " + n + " is "
- + factorial(new BigInteger(n)));
- }
- public static BigInteger factorial(BigInteger n) {
- if (n.equals(BigInteger.ZERO))
- return BigInteger.ONE;
- else
- return n.multiply(factorial(n.subtract(BigInteger.ONE)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement