Guest User

Untitled

a guest
Jan 12th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  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. }
Add Comment
Please, Sign In to add comment