Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class roots
- {
- public static void main(String args[])
- {
- InputStreamReader istream = new InputStreamReader(System.in) ;
- BufferedReader bufRead = new BufferedReader(istream) ;
- System.out.println("Enter integers A B and C for roots");
- try{
- String line = bufRead.readLine(); // to read multiple integers line
- BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
- String b=br.readLine();
- int x=Integer.parseInt(b);
- b=br.readLine();
- int x1=Integer.parseInt(b);
- b=br.readLine();
- int x2=Integer.parseInt(b);
- double d = x1 * x1 - 4 * x * x2;
- if(d > 0)
- {
- Double root1 = ( - x1 + Math.sqrt(d))/(2*x);
- Double root2 = (-x1 - Math.sqrt(d))/(2*x);
- System.out.println("First root is:"+root1);
- System.out.println("Second root is:"+root2);
- }
- else if(d == 0)
- {
- Double root1 = (-x1+Math.sqrt(d))/(2*x);
- System.out.println("Root:"+root1);
- }
- else
- {
- System.out.println("Roots are imaginary");
- }
- } catch (Exception err) {
- System.out.println("Error reading line");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement