Rispondi a: Lezione 11, esercizio 5

Blog Forum Java Lezione 11, esercizio 5 Rispondi a: Lezione 11, esercizio 5

#5749
Lux
Partecipante
Up
0
Down
::

Forse quello che cerchi è quello sulle equazioni di secondo grado… in caso affermativo:

Scanner scan = new Scanner(System.in);
System.out.println(“Inserire a: “);
double a= scan.nextInt();
System.out.println(“Inserire b: “);
double b = scan.nextInt();
System.out.println(“Inserire c: “);
double c= scan.nextInt();
double delta = (b*b)-4*a*c;
double x1,x2;
if (delta ==0)
{
x1=(-b -Math.sqrt(b*b-4*a*c)/(2*a));
x2=x1;
System.out.println(“Soluzioni coincidenti ” + x1);
}
if (delta >0)
{
x1=((-b -Math.sqrt(b*b-4*a*c))/(2*a));
x2=((-b +Math.sqrt(b*b-4*a*c))/(2*a));
System.out.println(“Soluzioni reali: ” + x1 + ” ” +x2 );
}
if (delta <0)
{
System.out.println(“Soluzioni complesse”);
}
}
}