Guest User

Untitled

a guest
Oct 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Main {
  6.  
  7. static class Triangle {
  8. private double a, h, S;
  9.  
  10. void setA(double a) {
  11. this.a = a;
  12. }
  13.  
  14. void setH(double h) {
  15. this.h = h;
  16. }
  17.  
  18. void getS() {
  19. System.out.println(S = ((a * h) / 2.0));
  20. }
  21. }
  22.  
  23. static class Circle {
  24. private double r, length;
  25.  
  26. void setRadius(double r) {
  27. this.r = r;
  28. }
  29.  
  30. void getCircleLength() {
  31. System.out.println(length = 2 * Math.PI * r);
  32. }
  33. }
  34.  
  35. public static void main(String[] args) {
  36. // 1
  37. System.out.print("Введите число: ");
  38. Scanner in = new Scanner(System.in);
  39. String number;
  40. for (; true; ) {
  41. number = in.next();
  42. if (number.length() == 6) {
  43. System.out.println("\nРезультат:");
  44. for (int i = 0; i < number.length(); i++) {
  45. System.out.println(number.charAt(i));
  46. }
  47. break;
  48. }
  49. }
  50.  
  51. // 2
  52. Scanner in = new Scanner(System.in);
  53. Triangle triangle = new Triangle();
  54. System.out.print("Введите длину основания треугольника: ");
  55. triangle.setA(in.nextDouble());
  56. System.out.print("Введите высоту треугольника: ");
  57. triangle.setH(in.nextDouble());
  58. System.out.print("Площадь треугольника: ");
  59. triangle.getS();
  60.  
  61. // 3
  62. Scanner in = new Scanner(System.in);
  63. Circle circle = new Circle();
  64. System.out.print("Введите радиус круга: ");
  65. circle.setRadius(in.nextDouble());
  66. circle.getCircleLength();
  67. }
  68. }
Add Comment
Please, Sign In to add comment