Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package projekt1;
- /*
- final - stała (w zmiennej)
- final w klasie (nie można z tej klasy dziedziczyć)
- */
- public class klasa1 {
- public static void main(String[] args) {
- double a = 0, b = 0, c = 0;
- //ciągnięcie z linii komend
- a = Double.parseDouble(args[0]);
- b = Double.parseDouble(args[1]);
- c = Double.parseDouble(args[2]);
- //final double a = 10;
- //final double b = 4;
- //final double c = 2;
- double delta = Math.pow(b, 2) - 4 * a * c;
- if(delta < 0) {
- System.out.println("Brak pierwiastków");
- }
- else {
- double sqrtDelta = Math.sqrt(delta);
- if(delta > 0) {
- System.out.println("x1 = "+Double.toString((-b - sqrtDelta)/(2*a)));
- //Double.toString <- nie jest wymagane jest wykonywane niejawnie przez kompilator
- System.out.println("x2 = "+(-b + sqrtDelta)/(2*a));
- }else {
- System.out.println("x1 = "+(-b)/(2*a));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement