Enter seconds: 3669
hours: 1, minutes: 1, seconds: 9
Exercise - Roots of a quadratic equation
נוסחת השורשים
x=2a−b±b2−4ac
determinant=b2−4ac
importjava.util.Scanner;publicclassMain {publicstaticvoidmain(String[] args) {double secondRoot =0, firstRoot =0;Scanner sc =newScanner(System.in);System.out.print("Enter the value of a: ");double a =sc.nextDouble();System.out.print("Enter the value of b: ");double b =sc.nextDouble();System.out.print("Enter the value of c: ");double c =sc.nextDouble();double determinant = (b*b)-(4*a*c);double sqrt =Math.sqrt(determinant);if(determinant>0){ firstRoot = (-b + sqrt)/(2*a); secondRoot = (-b - sqrt)/(2*a);System.out.println("Roots are: "+ firstRoot +" and "+secondRoot); }elseif(determinant ==0){System.out.println("Root is : "+(-b + sqrt)/(2*a)); } }}
Enter the value of a: 1
Enter the value of b: -1
Enter the value of c: -6
Roots are: 3.0 and -2.0
(x+2)(x−3)=0x2−1x−6=0
Exercise -Check if point is in radius of (x,y)
Hint: use Pythagorean theorem פיתגורס
Radius, diameter, & circumference | Circles (article) | Khan Academy
distance<radius
importjava.util.Scanner;publicclassMain {publicstaticvoidmain(String[] args) {Scanner sc =newScanner(System.in);//circleSystem.out.print("Enter x of circle: ");double x =sc.nextDouble();System.out.print("Enter y of circle: ");double y =sc.nextDouble();System.out.print("Enter radius: ");double radius =sc.nextDouble();//pointSystem.out.print("Enter x of point: ");double x_point =sc.nextDouble();System.out.print("Enter y of point: ");double y_point =sc.nextDouble();//calculationdouble delta_x = x - x_point;double delta_y = y - y_point;double distance =Math.sqrt(Math.pow(delta_x,2) +Math.pow(delta_y,2));if (distance < radius)System.out.println("Point is inside circle");elseif (distance == radius)System.out.println("Point is on the circles perimeter");elseSystem.out.println("Point is outside circle"); }}
Enter x of circle: 6
Enter y of circle: 0
Enter radius: 5
Enter x of point: 3
Enter y of point: -4
Point is on the circles perimeter
another run
Enter x of circle: 0
Enter y of circle: 0
Enter radius: 5
Enter x of point: 5.1
Enter y of point: 0
Point is outside circle