Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package lab3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class lab3part1 {
  6. public static void main (String[] args) {
  7.  
  8. Scanner input = new Scanner(System.in);
  9.  
  10. System.out.println(
  11. "\nFeet Meters | Meters Feet\n" +
  12. "----------------------------------------------");
  13. for (double feet = 1.0, meters = 20.0; feet <= 10.0; feet++, meters += 5)
  14. {
  15. System.out.printf("%4.1f ", feet);
  16.  
  17. System.out.printf("%6.3f", footToMeter(feet));
  18.  
  19. System.out.print(" | ");
  20.  
  21. System.out.printf("%-11.1f", meters);
  22.  
  23. System.out.printf("%7.3f\n", meterToFoot(meters));
  24.  
  25. }
  26. }
  27.  
  28.  
  29. public static double footToMeter(double foot) {
  30. return 0.305 * foot;
  31. }
  32.  
  33.  
  34. public static double meterToFoot(double meter) {
  35. return 3.279 * meter;
  36. }
  37.  
  38.  
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83. package lab3;
  84.  
  85. import java.util.Scanner;
  86.  
  87. public class lab3part2 {
  88.  
  89. public static void main(String[] args) {
  90. Scanner input = new Scanner(System.in); // Create a Scanner
  91.  
  92.  
  93. System.out.print("Enter the number of sides: ");
  94. int n = input.nextInt();
  95. System.out.print("Enter the side: ");
  96. double side = input.nextDouble();
  97.  
  98.  
  99. System.out.println("The area of the polygon is " + area(n, side));
  100.  
  101. }
  102.  
  103.  
  104. public static double area(int n, double side) {
  105. return (n * Math.pow(side, 2) / (4 * Math.tan(Math.PI / n)));
  106. }
  107. }
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164. package lab3;
  165.  
  166. import java.util.Scanner;
  167. import java.math.*;
  168.  
  169.  
  170.  
  171. public class lab3part3 {
  172.  
  173. public static void main(String[] args) {
  174.  
  175. Scanner input = new Scanner(System.in);
  176. System.out.print("Enter an integer: ");
  177. String n = input.nextLine();
  178.  
  179.  
  180. System.out.println("Factorial of " + n + " is "
  181. + factorial(new BigInteger(n)));
  182. }
  183.  
  184.  
  185. public static BigInteger factorial(BigInteger n) {
  186. if (n.equals(BigInteger.ZERO))
  187. return BigInteger.ONE;
  188. else
  189. return n.multiply(factorial(n.subtract(BigInteger.ONE)));
  190. }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement