Advertisement
n4wn4w

JAVA HOMEWORKS

Apr 8th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.80 KB | None | 0 0
  1. Homework: Introduction to Java/////////////////////////////////////////////////////////
  2.  
  3. 5 zadacha
  4.                 LocalDateTime today = LocalDateTime.now();
  5.         System.out.println("Today is: " + today);
  6.         LocalDateTime tomorrow = today.plusDays(1);
  7.         System.out.println("Tomorrow will be: " + tomorrow);
  8.  
  9.  
  10. 6 zadacha
  11.  
  12.                 Scanner input = new Scanner(System.in);
  13.         int numa = input.nextInt();
  14.         Scanner input1 = new Scanner(System.in);
  15.         int numb = input1.nextInt();
  16.        
  17.         int sum = numa + numb;
  18.        
  19.         System.out.println(sum);
  20.  
  21.  
  22. 8 zadacha
  23.  
  24.                 Scanner scanner = new Scanner(System.in);
  25.                 int n = scanner.nextInt();
  26.                 scanner.nextLine();
  27.                 String[] lines = new String[n];
  28.                 for (int i = 0; i < n; i++) {
  29.                         lines[i] = scanner.nextLine();
  30.                  }
  31.                 // Sort the array of strings
  32.                 Arrays.sort(lines);
  33.                 System.out.println();
  34.                 System.out.println();
  35.                 // Print the sorted array
  36.                 for (int i = 0; i < lines.length; i++) {
  37.                         System.out.println(lines[i]);
  38.                 }
  39.  
  40.  
  41. Homework: Java Syntax////////////////////////////////////////////////////////////////////////////////////
  42.  
  43.  
  44. Problem 1Rectangle Area
  45.  
  46.                  Scanner input = new Scanner(System.in);
  47.                  System.out.printf("pravougulnik- visochina = ",input);
  48.                  int numa = input.nextInt();
  49.                  Scanner input1 = new Scanner(System.in);
  50.                  System.out.printf("pravougulnik- duljina = ",input1);
  51.                  int numb = input1.nextInt();
  52.  
  53.                  int sum = numa * numb;
  54.                  System.out.printf("pravougulnik area = " + sum);
  55.  
  56.  
  57. Problem 2Triangle Area
  58.  
  59.              Scanner input = new Scanner(System.in);
  60.              int ax = input.nextInt();
  61.              Scanner input1 = new Scanner(System.in);
  62.              int ay = input1.nextInt();
  63.              Scanner input2 = new Scanner(System.in);
  64.              int bx = input.nextInt();
  65.              Scanner input3 = new Scanner(System.in);
  66.              int by = input1.nextInt();
  67.              Scanner input4 = new Scanner(System.in);
  68.              int cx = input.nextInt();
  69.              Scanner input5 = new Scanner(System.in);
  70.              int cy = input1.nextInt();
  71.    
  72.            
  73.  
  74.     double a = Math.sqrt(Math.pow((cx - bx),2)+Math.pow((cy - by),2));
  75.     double b = Math.sqrt(Math.pow((cx - ax),2)+Math.pow((cy - ay),2));
  76.     double c = Math.sqrt(Math.pow((bx - ax),2)+Math.pow((by - ay),2));
  77.  
  78.             if(a + c > c && a + c > b && b + c > a)
  79.             {
  80.                double p = (a + b + c) / 2;
  81.                double area = Math.sqrt(p*(p-a)*(p-b)*(p-c));
  82.                area = Math.round(area);
  83.                
  84.                System.out.println("Yes");
  85.                System.out.println((int)area);
  86.             }
  87.             else
  88.             {
  89.                 System.out.println("No");
  90.                c = Math.round(c,2); // tova e dr variant da zakruglqm do 2 znam ako napisha 3 she go zakrugli do 3 znak
  91.  
  92.                System.out.printf("{0:0.00}", c);
  93.             }
  94.             }
  95.  
  96.  
  97.  
  98.  problem 3 points inside figure
  99.  
  100.                 //          Scanner input = new Scanner(System.in);
  101.                 //                      int h = input.nextInt();
  102.             //              double h = 2.5;
  103.              
  104.  
  105.             for (int i = 0; i < 10; i++)
  106.             {
  107.                  //////// X
  108.                 Scanner input1 = new Scanner(System.in);
  109.                 double x = input1.nextDouble();
  110.                 ///////// Y
  111.                 Scanner input2 = new Scanner(System.in);
  112.                 double y = input2.nextDouble();
  113.  
  114.                 boolean box1 = ((x >= 12.5 && x <= 22.5) && (y >= 6 && y <= 8.5));
  115.                 boolean box2 = ((x >= 12.5 && x <= 17.5) && (y >= 8.5 && y <= 13.5));
  116.                 boolean box3 = ((x >= 20.0 && x <= 22.5) && (y >= 8.5 && y <= 13.5));
  117.                
  118.                 if (box1 || box2 || box3)// moje i s if 1 zadachi C# 8 variant
  119.                 {
  120.                         System.out.println("inside");
  121.                 }
  122.                 else
  123.                 {
  124.                         System.out.println("outside");
  125.                }
  126.             }
  127.  
  128.  
  129. Problem 4The Smallest of 3 Numbers
  130.  
  131.                  Scanner input = new Scanner(System.in);
  132.                  System.out.printf("A ",input);
  133.                  double numa = input.nextDouble();
  134.                  Scanner input1 = new Scanner(System.in);
  135.                  System.out.printf("B ",input1);
  136.                  double numb = input1.nextDouble();
  137.                  Scanner input2 = new Scanner(System.in);
  138.                  System.out.printf("C ",input1);
  139.                  double numc = input2.nextDouble();
  140.  
  141.                  
  142.                  double Smallest = 0;
  143.                  
  144.                  if(numa > numb){
  145.                      Smallest = numb;
  146.                  }
  147.                  else  {
  148.                     Smallest = numa;
  149.                  }
  150.                  if(numc < Smallest){
  151.                      Smallest = numc;
  152.                  }
  153.                  
  154.                  System.out.printf("Smallest " + Smallest);
  155.  
  156.  
  157.  
  158.  
  159.  problem 9 .Points inside the House
  160.  
  161.                 for (int i =0; i <= 20; i++){
  162.                ///////////// x
  163.                Scanner input = new Scanner(System.in);
  164.                double x = input.nextDouble();
  165.                ////////////// y
  166.                Scanner input1 = new Scanner(System.in);
  167.                double y = input1.nextDouble();
  168.  
  169.                  
  170.                  
  171.                  double x1 = 12.5;  
  172.                  double x2 = 17.5;
  173.                  double x3 = 22.5;
  174.                  double y1 = 8.5;
  175.                  double y2 = 3.5;
  176.                  double y3 = 8.5;
  177.                  //////////////////////////////////
  178.                  
  179.                  
  180.                  double ABC = Math.abs (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2));
  181.                  double ABP = Math.abs (x1 * (y2 - y) + x2 * (y - y1) + x * (y1 - y2));
  182.                  double APC = Math.abs (x1 * (y - y3) + x * (y3 - y1) + x3 * (y1 - y));
  183.                  double PBC = Math.abs (x * (y2 - y3) + x2 * (y3 - y) + x3 * (y - y2));
  184.  
  185.                  ///// triugulnik
  186.               boolean isInTriangle = ABP + APC + PBC == ABC;
  187.                /////////  kvadrati
  188.               boolean box1 = ((x >= 12.5 && x <= 17.5) && (y >= 8.5 && y <= 13.5));
  189.               boolean box2 = ((x >= 20.0 && x <= 22.5) && (y >= 8.5 && y <= 13.5));
  190.  
  191.  
  192.              if (isInTriangle || box1 || box2)
  193.              {
  194.                  System.out.println("inside");
  195.              }
  196.                 else
  197.                 {
  198.                     System.out.println("outside");
  199.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement