Task 1: Scrieti un program Java care sa sorteze crescator trei numere reale citite de la
tastatura.
Task 2: Scrieti un program Java care sa rezolve o ecuatie de grad doi cu coeficienti
reali.
Răspunsuri la întrebare
TASK 1:
import java.util.Scanner;
public class HelloWorld {
public static void main(String []args) {
Scanner scan = new Scanner(System.in);
System.out.print("a,b,c : ");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int minim, mij, maxim;
if(a <= b && a <= c) minim = a;
else if(b<=c && b <= a) minim = b;
else minim=c;
if(a >= b && a >= c) maxim = a;
else if(b>=c && b >= a) maxim = b;
else maxim=c;
mij = a+b+c-minim-maxim;
System.out.println(minim+" "+mij+" "+maxim);
}
}
TASK 2:
import java.util.Scanner;
import java.lang.Math;
public class HelloWorld {
public static void main(String []args) {
Scanner scan = new Scanner(System.in);
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int delta = b*b-4*a*c;
if(delta < 0){
System.out.println("Nu exista solutii");
}
else if(delta==0){
System.out.println("x = "+(-b/(2*a)));
}
else {
System.out.println("\nx1 = "+(-b+Math.sqrt(delta))/(2*a));
System.out.println("\nx2 = "+(-b-Math.sqrt(delta))/(2*a));
}
}
}