fork download
  1. //package com.Class1;
  2. import java.lang.*;
  3. import java.util.Scanner;
  4.  
  5. class Ideone {
  6.  
  7. public static void main(String[] args) {
  8. Scanner in = new Scanner(System.in);
  9.  
  10. System.out.println("Insira o valor de a:");
  11. int a = in.nextInt();
  12.  
  13. System.out.println("Insira o valor de b:");
  14. int b = in.nextInt();
  15.  
  16. System.out.println("Insira o valor de c:");
  17. int c = in.nextInt();
  18.  
  19. double pB = Math.pow(b, 2);
  20. double delta = pB - 4 * a * c;
  21. double x1 = -1 * pB + Math.sqrt(Math.abs(delta)) / 2 * a;
  22. double x2 = -1 * pB - Math.sqrt(Math.abs(delta)) / 2 * a;
  23.  
  24. double r1 = Math.round(x1);
  25. double r2 = Math.round(x2);
  26.  
  27. if(delta < 0) {
  28. System.out.println("A raíz x1 vale: "+ x1 + "i");
  29. System.out.println("A raíz x2 vale: "+ x2 + "i");
  30. } else {
  31. System.out.println("A raíz x1 vale: "+ x1);
  32. System.out.println("A raíz x2 vale: "+ x2);
  33. }
  34. }
  35. }
Success #stdin #stdout 0.06s 711680KB
stdin
3
4
5
stdout
Insira o valor de a:
Insira o valor de b:
Insira o valor de c:
A raíz x1 vale: -6.050125628933801i
A raíz x2 vale: -25.9498743710662i