Advertisement
wintest

2ра лекциш

Mar 7th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. package javaapplication30;
  2.  
  3. import java.lang.Math;
  4.  
  5. public class JavaApplication30 {
  6.  
  7.     /* public static void equation(double a, double b, double c){
  8.         double D = Math.pow(b, 2) - (4 * a * c);
  9.         if (D < 0) {
  10.             System.out.println("No solutions: D < 0.");
  11.         } else if (D == 0) {
  12.             System.out.print("There is one solution (D = 0): x = ");
  13.             double x = -b / (c * a);
  14.             System.out.println(x);
  15.         } else if (D > 0) {
  16.             System.out.println("There are two solutions (D > 0): x1 = ");
  17.             double x1 = (-b + Math.sqrt(D)) / 2 * a;
  18.             System.out.print(x1 + ", x2 = ");
  19.             double x2 = (-b - Math.sqrt(D)) / 2 * a;
  20.             System.out.println(x2);
  21.         }
  22.     }*/
  23.  /* public static void evenNumbers(int low, int high) {
  24.         System.out.print("Even numbers in [" + low + ", " + high + "]: ");
  25.         for (int i = low; i <= high; i++) {
  26.             if (i % 2 == 0){
  27.                 System.out.print(i + " ");
  28.             }
  29.         }
  30.         System.out.println("");
  31.     }*/
  32.  /*public static double average(int low, int high) {
  33.         double sum = 0;
  34.         int counter = 0;
  35.         for (double i = low; i <= high; i++) {
  36.             if ((i % 5 == 0) && (i % 3 != 0)){
  37.                 sum += i;
  38.                 counter += 1;
  39.             }
  40.         }
  41.         double average = sum / counter;
  42.         System.out.println("Average: " + average);
  43.         return average;
  44.     }*/
  45.    
  46.     public static int sumOfDividers(int number) {
  47.         int sum = 0;
  48.        
  49.  
  50.         for (int i = 0; i < number; i++) {
  51.             if ((i > 0) && (number % i == 0)) {
  52.                 //System.out.print(i + " ");
  53.                 sum += i;
  54.             }
  55.         }
  56.         System.out.println("Sum of dividers = " + sum);
  57.         return sum;
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement