Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.lang.Math;
- public class Calc {
- public static void main (String args[]) throws IOException {
- System.out.println("Enter data");
- InputStream key = System.in;
- Reader keyReader = new InputStreamReader(key);
- BufferedReader keyBuffer = new BufferedReader(keyReader);
- String oneString = keyBuffer.readLine();
- String twoString = keyBuffer.readLine();
- String threeString = keyBuffer.readLine();
- int x;
- double x1;
- double x2;
- int a = Integer.parseInt(oneString);
- int b = Integer.parseInt(twoString);
- int c = Integer.parseInt(threeString); // a(x*x)+bx-c=0
- double d = Math.pow(b,2)-4*a*c;
- if (d<0) {
- System.out.println("Have no solution");
- }
- else if (d==0) {
- x = -b/2*a;
- System.out.println("Solution is: "+x);
- }
- else if (d>0) {
- x1 = ((-b)+Math.sqrt(d))/(2*a);
- x2 = ((-b)-Math.sqrt(d))/(2*a);
- System.out.println("Solution is: "+x1 +","+x2);
- }
- System.out.println(d);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement