daily pastebin goal
48%
SHARE
TWEET

Untitled

a guest Jan 12th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class a006{
  5.  
  6.     public static void main(String[] args){
  7.  
  8.         Scanner keyin = new Scanner(System.in);
  9.         int a, b, c;
  10.         int x1, x2;
  11.     int inSqrt, sqrt;
  12.    
  13.         while(keyin.hasNext()){
  14.             a = keyin.nextInt();
  15.             b = keyin.nextInt();
  16.             c = keyin.nextInt();
  17.         inSqrt = (int) Math.pow(b,2) - (4 * a * c);
  18.  
  19.         if(inSqrt < 0)
  20.                 System.out.println("No real root");
  21.  
  22.         else if(inSqrt == 0){
  23.             x1 = -b / (2*a);
  24.                 System.out.println("Two same roots x=" + x1);
  25.         }
  26.  
  27.         else{
  28.                 sqrt =(int) Math.sqrt( inSqrt ) ;
  29.                 x1 = ( (-b + sqrt) / (2*a)) ;
  30.                 x2 = ( (-b - sqrt) / (2*a)) ;
  31.                 System.out.println("Two different roots x1=" + x1 +" , x2="+ x2);
  32.    
  33.             }
  34.         }
  35.     }
  36.  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top