Posts

Perform Addition of Two Numbers in Java | Java Programs

Output: *** Addition Of Two Numbers *** The first number is: 10 The second number is: 20 The sum of the 10 and 20 is: 30 Click Here For  Java Online Compiler Solution: class AdditionOfTwoNumbers { public static void main ( String [] args ) { int firstNumber = 10; int secondNumber = 20; int sum = firstNumber + secondNumber ; System . out . println ( "*** Addition Of Two Numbers ***" + "\n" ); System . out . println ( "The first number is: " + firstNumber ); System . out . println ( "The second number is: " + secondNumber ); System . out . println ( "The sum of the " + firstNumber + " and " + secondNumber + " is: " + sum ); } }

Find Largest Of 3 Numbers Using "Nested-If" | Java Programs

Output: *** Largest of 3 Number Using Nested If *** The Three Numbers are: 103, 120, 70. The largest number is: 120 Click Here For  Java Online Compiler Solution: public class LargestOf3NumbersUsingNestedIf { public static void main ( String [] args ) { int num1 = 103, num2 = 120, num3 = 70; System . out . println ( "*** Largest of 3 Number Using Nested If ***" + "\n" ); System . out . println ( "The Three Numbers are: " + num1 + ", " + num2 + ", " + num3 + "." ); System . out . println (); if ( num1 >= num2 ) { if ( num1 >= num3 ) { System . out . println ( "The largest number is: " + num1 ); } else { System . out . println ( "The largest number is: " + num3 ); } } else { if ( num2 >= num3 ) { ...

Print Java | Java Programs

Output: J a v v a J a a v v a a J J aaaaa V V aaaaa JJ a a V a a Click Here For  Java Online Compiler Solution: class PrintBasic { public static void main ( String [] args ) { System . out . println ( " J a v v a " ); System . out . println ( " J a a v v a a" ); System . out . println ( "J J aaaaa V V aaaaa" ); System . out . println ( " JJ a a V a a" ); } }

Find whether a number is positive, negative or zero | Java Programs

Output: *** Positive Or Negative Or Zero *** Enter any number: -4 The number is negative . ------------------------------------ *** Positive Or Negative Or Zero *** Enter any number: 18 The number is positive . ------------------------------------ *** Positive Or Negative Or Zero *** Enter any number: 0 The number is zero . Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class PositiveOrNegativeOrZero { public static void main ( String [] args ) { Scanner obj = new Scanner ( System . in ); System . out . println ( "*** Positive Or Negative Or Zero ***" + "\n" ); System . out . println ( "Enter any number: " ); int num = obj . nextInt (); if ( num > 0) { System . out . println ( "The number is positive." ); } else if ( num < 0) { System . out . println ( "The number is negativ...

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 ); } } }

Generate Random Numbers | Java Programs

Output: Random Numbers: *************** 47 60 18 9 67 ---------------- Random Numbers: *************** 78 68 14 79 69 Click Here For  Java Online Compiler Solution: import java.util.* ; class GenerateRandomNumbers { public static void main ( String [] args ) { Random r = new Random (); int howManyRandom = 5; System . out . println ( "Random Numbers:" ); System . out . println ( "***************" ); for ( int i = 1; i <= howManyRandom ; i ++) { System . out . println ( r . nextInt (100)); //Here 100 shows that random number } //will not exceed 100 } }

Finding Factorial Using "For Loop" | Java Programs

Output: *** Factorial Using For LOOp Only *** Find Factorial Of: 4 Factorial of 4 is: 24 Click Here For  Java Online Compiler Solution: import java.util.Scanner ; class FactorialUsingForLoop { public static void main ( String [] args ) { Scanner scanner = new Scanner ( System . in ); System . out . println ( "*** Factorial Using For LOOp Only ***" + "\n" ); System . out . print ( "Find Factorial Of: " ); int factorialOf = scanner . nextInt (); long fact = 1; for ( int i = 1; i <= factorialOf ; i ++) { fact = fact * i ; } System . out . println ( "Factorial of " + factorialOf + " is: " + fact ); } }