Skip to content

Instantly share code, notes, and snippets.

@Lotuashvili
Created December 2, 2014 20:04
Show Gist options
  • Save Lotuashvili/41e3aad70f26c917aad9 to your computer and use it in GitHub Desktop.
Save Lotuashvili/41e3aad70f26c917aad9 to your computer and use it in GitHub Desktop.
კვადრატული განტოლება (Java)
import java.util.Scanner;
public class Quadratic {
public static void main(String[] args) {
double a,b,c,d,x1,x2;
Scanner scanner = new Scanner(System.in);
System.out.print("Sheiyvanet a koeficienti: ");
a = scanner.nextDouble();
System.out.print("Sheiyvanet b koeficienti: ");
b = scanner.nextDouble();
System.out.print("Sheiyvanet c koeficienti: ");
c = scanner.nextDouble();
d = b*b - 4*a*c;
if (d < 0)
System.out.println("Gantolebas amonaxsni ar akvs");
else if (d == 0) {
x1 = -b / (2*a);
System.out.println("Gantolebas akvs erti amonaxsni: " + x1);
} else if (d > 0) {
x1 = Math.round( ((-b - Math.sqrt(d)) / (2*a)) * 1000.0) / 1000.0;
x2 = Math.round( ((-b + Math.sqrt(d)) / (2*a)) * 1000.0) / 1000.0;
System.out.println("Gantolebis amonaxsnebi:");
System.out.println("x1 = " + x1);
System.out.println("x2 = " + x2);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment