I need help with this problem in JAVA, i'm doing a various methdos using Scanner. I have to do the next program for the quadratic equation:
This method calculates the quadratic equation (both roots) and print both results. Note: this method does not return anything, since it prints theresult by itself. In the main () method, the method must be invoked quadratic with the corresponding parameters. The signature of the quadratic method is: Public static void quadratic (int a, int b, int c) Method: Quadratic You must validate that the division can NOT be calculated with a denominator of zero. If the denominator is 0 (zero) you must print a message that indicates this. You must validate that the value within the square root must be greater than or equal to zero, otherwise you must print a message that indicates this.
Thank you very much
import java.util.Scanner;
public class Quadratic {
public static void quadratic (int a, int b, int c) {
double d = b*b - 4*a*c;
if (d < 0 || a == 0) {
System.out.println("There are no real roots.");
} else {
d = Math.sqrt(d);
System.out.println("Roots are " + ((-b+d)/(2*a)) + " and " + ((-b-d)/(2*a)));
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a, b and c as integers: ");
int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
quadratic(a, b, c);
in.close();
}
}
I need help with this problem in JAVA, i'm doing a various methdos using Scanner. I...
Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...
Hey, need some help in Java. I'm stuck on one step that prevents me from doing the rest of the steps and need help on it. I also have a problem when I print databaseCourse and programmingCourse. instead of saying 5 and 7 respectively is shows 51 and 71. Step 8: in CourseGrades, create a method, add, that takes two parameters, studentNum and grade, and changes the grade of student studetNum to the given grade, grade. studentNum represents the student...
Add another public method called add to your Fraction class. This method adds another fraction to the ‘calling object’. Thus, the method will take a Fraction class object as a parameter, add this parameter fraction to the calling object (fraction), and return a Fraction object as a result. HINT: We can use cross multiplication to determine the numerator of the resultant Fraction. The denominator of the resultant Fraction is simply the multiplication of the denominators of the two other Fractions.Add...
Java Programming Question. I am writing a code to calculate the roots of the quadratic equation based on the values of the coefficients A, B, and C. I am supposed to enter 5 values for each coefficient, and the output should be five different answers (see example) using a for loop and if else statements. However, when I run my code, I am only able to enter one value for each coefficient and the output is one answer repeated five...
IN JAVA Overview In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide the user to decide between different forms...
Hello, I need help writing the two methods to print a triangle shape in java. An example of the shape is as follows: 9 8 7 6 5 4 3 8 7 6 5 4 3 7 6 5 4 3 6 5 4 3 5 4 3 4 3 3 One method should be defined as "public static void printPattern(int num1, int num2, Boolean ascending)". This method will print a upper-triangle matrix-like layout filled will a sequence of integers...
This is java. I need help with my computer science class. Question 11 Assume that you have an array of integers named arr. The following program segment is intended to sum arr [0]through arr[n−1], where n = arr.length: sum = 0; i = 0; n = arr.length; while (i != n) { i++; sum += arr[i]; } In order for this segment to perform as intended, which of the following modifications, if any, should be made? 1.No modification is necessary...
HELLO. I'M KINDA NEW TO JAVA AND I NEED HELP WITH A METHOD. USING RECURSION ONLY. public static int sumaEnRango (int start,int end) -RECURSIVE METHOD THAT RETURNS THE SUM OF ALL THE CONSECUTIVE INTEGER NUMBERS BETWEEN "START" AND "END. IT ALSO RETURNS 0 IN CASE "START" IS GREATER THAN "END" THIS METHOD RETURNS AN ARITHMERIC EXCEPTION IN CASE THE PARAMETER NUMBER IS NEGATIVE I KNOW THIS IS SIMPLE METHOD BUT I'M STILL CONFUSED WHEN USING RECURSION. THANKS A LOT !!!
How would I code this method in Java using a scanner? Begin by asking how many spaces the row should be with a prompt using System.out.print like the following, with 40 as the maximally allowed number of spaces: (user input shown bold) Please enter the number of spaces for the game (1-40): eight To do this, use the promptNumberReadLine method that you will write, described on the back page. If the user does not type a number in the correct...
A quadratic equation is generally represented as, ax^2 + bx + c The root(s) of the above quadratic equation is computed using the following formula, root1 = (-b + sqrt(D))/ 2a root2 = (-b - sqrt(D))/2a Where D is the discriminant of the quadratic equation and is computed as, D = b^2 - 4ac Given the value of D, the roots of a quadratic equation can be categorized as follows, D > 0 : Two distinct real roots D =...