Boundary Value Analysis : Nature of Roots of a Quadratic equation | Java program to check the nature of the roots ; BVA for nature of roots of a quadratic equation ; If a = 0 , D / 2 a will yield exception Hence it is not a valid Quadratic Equation ; If D > 0 , it will be Real Roots ; If D == 0 , it will be Equal Roots ; If D < 0 , it will be Imaginary Roots ; Function to check for all testcases ; Driver Code
import java . util . * ; class GFG { static void nature_of_roots ( int a , int b , int c ) { if ( a == 0 ) { System . out . print ( " Not ▁ a ▁ Quadratic ▁ Equation " + "NEW_LINE"); return ; } int D = b * b - 4 * a * c ; if ( D > 0 ) { System . out . print ( " Real ▁ Roots " + "NEW_LINE"); } else if ( D == 0 ) { System . out . print ( " Equal ▁ Roots " + "NEW_LINE"); } else { System . out . print ( " Imaginary ▁ Roots " + "NEW_LINE"); } } static void checkForAllTestCase ( ) { System . out . print ( " Testcase " + " TABSYMBOL a TABSYMBOL b TABSYMBOL c TABSYMBOL Actual ▁ Output " + "NEW_LINE"); System . out . println ( ) ; int a , b , c ; a = b = c = 0 ; int testcase = 1 ; while ( testcase <= 13 ) { if ( testcase == 1 ) { a = 0 ; b = 50 ; c = 50 ; } else if ( testcase == 2 ) { a = 1 ; b = 50 ; c = 50 ; } else if ( testcase == 3 ) { a = 50 ; b = 50 ; c = 50 ; } else if ( testcase == 4 ) { a = 99 ; b = 50 ; c = 50 ; } else if ( testcase == 5 ) { a = 100 ; b = 50 ; c = 50 ; } else if ( testcase == 6 ) { a = 50 ; b = 0 ; c = 50 ; } else if ( testcase == 7 ) { a = 50 ; b = 1 ; c = 50 ; } else if ( testcase == 8 ) { a = 50 ; b = 99 ; c = 50 ; } else if ( testcase == 9 ) { a = 50 ; b = 100 ; c = 50 ; } else if ( testcase == 10 ) { a = 50 ; b = 50 ; c = 0 ; } else if ( testcase == 11 ) { a = 50 ; b = 50 ; c = 1 ; } else if ( testcase == 12 ) { a = 50 ; b = 50 ; c = 99 ; } else if ( testcase == 13 ) { a = 50 ; b = 50 ; c = 100 ; } System . out . print ( " TABSYMBOL " + testcase + " TABSYMBOL " + a + " TABSYMBOL " + b + " TABSYMBOL " + c + " TABSYMBOL " ) ; nature_of_roots ( a , b , c ) ; System . out . println ( ) ; testcase ++ ; } } public static void main ( String [ ] args ) { checkForAllTestCase ( ) ; } }