Advertisement
Guest User

Untitled

a guest
Jan 21st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. import java.io.*;
  2. import java.lang.Math;
  3.  
  4. public class Calc {
  5.     public static void main (String args[]) throws IOException {
  6.         System.out.println("Enter data");
  7.         InputStream key = System.in;
  8.         Reader keyReader = new InputStreamReader(key);
  9.         BufferedReader keyBuffer = new BufferedReader(keyReader);
  10.         String oneString = keyBuffer.readLine();
  11.         String twoString = keyBuffer.readLine();
  12.         String threeString = keyBuffer.readLine();
  13.         int x;
  14.         double x1;
  15.         double x2;
  16.         int a = Integer.parseInt(oneString);
  17.         int b = Integer.parseInt(twoString);
  18.         int c = Integer.parseInt(threeString); // a(x*x)+bx-c=0
  19.         double d = Math.pow(b,2)-4*a*c;
  20.         if (d<0) {
  21.             System.out.println("Have no solution");
  22.         }
  23.         else if (d==0) {
  24.             x = -b/2*a;
  25.             System.out.println("Solution is: "+x);
  26.         }
  27.         else if (d>0) {
  28.             x1 = ((-b)+Math.sqrt(d))/(2*a);
  29.             x2 = ((-b)-Math.sqrt(d))/(2*a);
  30.             System.out.println("Solution is: "+x1 +","+x2);
  31.         }
  32.         System.out.println(d);
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement