Posts

Showing posts with the label Mathematical Exercises

Find Perimeter Of Rectangle | Java Programs

Image
Perimeter of Rectangle Output: *** Perimeter Of Rectangle *** Enter the width of rectangle: 3 Enter the height of rectangle: 4 Perimeter is: 14.0 Try this compiler and compile Java code online! Click Here For   J a v a O n l i n e C o m p i l e r Solution: import java.util.Scanner ; public class PerimeterOfRectangle { public static void main ( String [] strings ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "*** Perimeter Of Rectangle ***" + "\n" ); System . out . print ( "Enter the width of rectangle: " ); double width = scanner . nextDouble (); System . out . print ( "Enter the height of rectangle: " ); double height = scanner . nextDouble (); double perimeter = 2 * ( height + width ); System . out . println (); System . out . println ( "Perimeter is: " + perimeter...

Take Number From User And Print Its Multiplication Table | Java Programs

Output: *** Multiplication Table *** Enter any number for its Multiplication Table: 9 9 x 1 = 9 9 x 2 = 18 9 x 3 = 27 9 x 4 = 36 9 x 5 = 45 9 x 6 = 54 9 x 7 = 63 9 x 8 = 72 9 x 9 = 81 9 x 10 = 90 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class PrintMultiplicationTable { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "*** Multiplication Table ***" + "\n" ); System . out . print ( "Enter any number for its Multiplication Table: " ); int number = scanner . nextInt (); for ( int i = 1; i <= 10; i ++) { System . out . println ( number + " x " + i + " = " + number * i ); } } }

Take Two Integers And Return "true" If Either One Is 10 Or Their Sum Or Difference is 10 | Java Programs

Output: Input the first integer number: 1 Input the second integer number: 9 The result is: true ----------------------------------- Input the first integer number: 15 Input the second integer number: 5 The result is: true ----------------------------------- Input the first integer number: 123 Input the second integer number: 10 The result is: true Click Here For  Java Online Compiler Solution: import java.util.Scanner ; public class AddOrDiffEquals10 { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . print ( "Input the first integer number: " ); int x = scanner . nextInt (); System . out . print ( "Input the second integer number: " ); int y = scanner . nextInt (); System . out . print ( "The result is: " + calculate ( x , y )); System . out . print ( "\n" ); } public static...

Find The Roots Of A Quadratic Equation | Java Programs

Output: *** Roots Of Quadratic Equation *** Enter a: 2 Enter b: 9 Enter c: 3 Given quadratic equation: 2 x ^2 + 9 x + 3 Roots are real and unequal First root is : -0.36254139118231254 Second root is : -4.1374586088176875 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; public class RootsOfEquation { public static void main ( String [] args ) { int a , b , c ; double root1 , root2 , d ; Scanner s = new Scanner ( System . in ); System . out . println ( "*** Roots Of Quadratic Equation ***" + "\n" ); System . out . print ( "Enter a: " ); a = s . nextInt (); System . out . print ( "Enter b: " ); b = s . nextInt (); System . out . print ( "Enter c: " ); c = s . nextInt (); System . out . println (); System . out . println ( "Given quadratic equation: ...

Convert Roman Number To An Integer | Java Programs

Output: This Program Needs A Little Improvement ! *** Roman Number To Integer Number *** Use These Symbols - I , V , X , L , C , D , M Enter Roman Number: DCLX Roman Number: DCLX Integer: 660 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; public class ConvertRomanToInteger { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "This Program Needs A Little Improvement!" + "\n" ); System . out . println ( "*** Roman Number To Integer Number ***" + "\n" ); System . out . println ( "Use These Symbols - I, V, X, L, C, D, M" ); System . out . print ( "Enter Roman Number: " ); String str = scanner . next (); int length = str . length (); str = str + " " ; int result = 0; for ( int i = 0; i ...

Reverse Any Integer Number | Java Programs

Output: *** Reverse An Integer *** Enter any number : 1234567 The Original Number is: 1234567 Reversed Number is : 7654321 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class ReverseAnInteger { public static void main ( String [] args ) { System . out . println ( "*** Reverse An Integer ***" + "\n" ); Scanner scanner = new Scanner ( System . in ); System . out . print ( "Enter any number : " ); int num = scanner . nextInt (); System . out . println ( "\nThe Original Number is: " + num ); int is_positive = 1; if ( num < 0) { is_positive = -1; num = -1 * num ; } int sum = 0; while ( num > 0) { int r = num % 10; int maxDiff = Integer . MAX_VALUE - sum * 10; if ( sum > Integer . MAX_VALUE / 10 ...

Take A Number From User And Check Whether It's Double Or Not | Java Programs

Output: *** Check Whether Any Number Is Double Or Not *** Enter any number: 930475 It's not a double number ------------------------------------------------- *** Check Whether Any Number Is Double Or Not *** Enter any number: 3452.56 It' s a double number Click Here For  Java Online Compiler Solution: import java.util.Scanner ; public class TestIfNumIsDouble { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "*** Check Whether Any Number Is Double Or Not ***" + "\n" ); System . out . print ( "Enter any number: " ); double number = scanner . nextDouble (); if (( number % 1) == 0) { System . out . println ( "It's not a double number" ); } else { System . out . println ( "It's a double number" ); } } }

Separate Whole And Fractional Parts From A "double" Number | Java Programs

Output: *** Whole and Fractional Parts In A Double Original number is : 12.368 Integral part : 12.0 Fractional part : 0.3680000000000003 Click Here For  Java Online Compiler Solution: class WholeFractionalOfDouble { public static void main ( String [] args ) { double anyNumber = 12.368; double fractional_part = anyNumber % 1; double integral_part = anyNumber - fractional_part ; System . out . println ( "*** Whole and Fractional Parts In A Double" + "\n" ); System . out . println ( "Original number is : " + anyNumber + "\n" ); System . out . println ( "Integral part : " + integral_part ); System . out . println ( "Fractional part : " + fractional_part ); } }

Round Up The Result Of Integer Division | Java Programs

Output: *** Rounding Up Integer Division *** Number 1 = 10 Number 2 = 3 Their division is : 3.333 Rounding Up : 3 Click Here For  Java Online Compiler Solution: class WholeFractionalOfDouble { public static void main ( String [] args ) { double anyNumber = 12.368; double fractional_part = anyNumber % 1; double integral_part = anyNumber - fractional_part ; System . out . println ( "*** Whole and Fractional Parts In A Double" + "\n" ); System . out . println ( "Original number is : " + anyNumber + "\n" ); System . out . println ( "Integral part : " + integral_part ); System . out . println ( "Fractional part : " + fractional_part ); } }

Calculate The Circumference Of Circle Taking Radius From User | Java Programs

Output: *** Circumference of Circle *** Enter The Radius of Circle: 25 Circumference of Circle is: 157.07963267948 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class CircumferenceOfCircle { static void circumference ( int radius ) { double cir = 2 * Math . PI * radius ; System . out . println ( "Circumference of Circle is: " + cir ); } public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "*** Circumference of Circle ***" + "\n" ); System . out . print ( "Enter The Radius of Circle: " ); int radius = scanner . nextInt (); circumference ( radius ); //call circumference method } }

Take Two Integers And Find Their HCF | Java Programs

Output: *** HCF Of Two Numbers *** Enter the first number: 3 Enter the second number: 4 HCF: 1 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class HCF { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); int dividend , divisor ; int remainder , hcf = 0; System . out . println ( "*** HCF Of Two Numbers ***" + "\n" ); System . out . print ( "Enter the first number: " ); dividend = scanner . nextInt (); System . out . print ( "Enter the second number: " ); divisor = scanner . nextInt (); do { remainder = dividend % divisor ; if ( remainder == 0) { hcf = divisor ; } else { dividend = divisor ; divisor ...