mjau

Kvadrātvienādojums

Oct 29th, 2011
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import java.lang.Math;
  2. import java.util.Scanner;
  3.  
  4. public class math {
  5.     public static void main(String[] args) {
  6.         Scanner ascan = new Scanner(System.in);
  7.         Scanner bscan = new Scanner(System.in);
  8.         Scanner cscan = new Scanner(System.in);
  9.         System.out.println("A veertiiba?");
  10.         String astring = ascan.nextLine();
  11.         System.out.println("B veertiiba?");
  12.         String bstring = bscan.nextLine();
  13.         System.out.println("C veertiiba?");
  14.         String cstring = cscan.nextLine();
  15.         int a = Integer.parseInt(astring);
  16.         int b = Integer.parseInt(bstring);
  17.         int c = Integer.parseInt(cstring);
  18.         int y;
  19.  
  20.         if (b > 0) {
  21.             int x = b * 2;
  22.             y = b - x;
  23.         }else{
  24.             int x = b * (-2);
  25.             y = b + x;
  26.         }
  27.  
  28.         int l = a * 2;
  29.         int m = (b * b) - (4 * a * c);
  30.         double n = Math.sqrt(m);
  31.         double o = y + n;
  32.         double p = y - n;
  33.         double f1 = o / l;
  34.         double f2 = p / l;
  35.  
  36.         System.out.println("x1 = " + f1);
  37.         System.out.println("x2 = " + f2);
  38.            
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment