Created
November 21, 2023 23:12
-
-
Save rafarocha/ed4e6cbc0d0e5805b2f15aa7120104dd to your computer and use it in GitHub Desktop.
turma-1076-desafio01-feedback-sylas-clozel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
import static java.lang.Math.pow; | |
public class Main { | |
public static void main(String[] args) { | |
double a,b,c,delta,x1,x2; | |
System.out.println("Digite os números de uma equação do segundo grau "); | |
System.out.println("Digite a"); | |
Scanner leitor = new Scanner(System.in); | |
System.out.print(">"); | |
a = leitor.nextDouble(); | |
if (a != 0) { | |
System.out.print(">"); | |
b = leitor.nextDouble(); | |
System.out.print(">"); | |
c = leitor.nextDouble(); | |
delta = (pow(b, 2) - 4 * a * c); | |
if (delta < 0) { | |
System.out.println("Não existe raiz no conjunto dos reais"); | |
} else if (delta == 0) { | |
x1 = ((b + delta) / 2 * a); | |
System.out.println("As raizes x1 e x2 são iguais = " + x1); | |
} else { | |
x1 = (b - delta) / (2 * a); | |
x2 = (b + delta) / (2 * a); | |
System.out.printf(" as raizes são: x1 = %.2f e x2 = %.2f ", x1, x2); | |
} | |
} else { | |
System.out.println("A equação não é do segundo grau"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Revisão
Melhorias
Desafio 03
sobre ter linhas juntas. Conferir aqui!(a,b,c)=(1,-3,2)
retornou o resultado errado-2 e -1
, para o cenário 01(a,b,c)=(4,4,1)
retornou o resultado errado8.0
, para o cenário 02(a,b,c)=(12345,-54321,9876)
retornou o resultadox1 = -99763.00 e x2 = 99758.60
, para o cenário 05Referências