Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class a006{
- public static void main(String[] args){
- Scanner keyin = new Scanner(System.in);
- int a, b, c;
- int x1, x2;
- int inSqrt, sqrt;
- while(keyin.hasNext()){
- a = keyin.nextInt();
- b = keyin.nextInt();
- c = keyin.nextInt();
- inSqrt = (int) Math.pow(b,2) - (4 * a * c);
- if(inSqrt < 0)
- System.out.println("No real root");
- else if(inSqrt == 0){
- x1 = -b / (2*a);
- System.out.println("Two same roots x=" + x1);
- }
- else{
- sqrt =(int) Math.sqrt( inSqrt ) ;
- x1 = ( (-b + sqrt) / (2*a)) ;
- x2 = ( (-b - sqrt) / (2*a)) ;
- System.out.println("Two different roots x1=" + x1 +" , x2="+ x2);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment