Programs
Pascal's Triangle
This article intends to show the different ways to print a Pascal’s triangle and also format it so that it looks like an iso ... rint(“Enter the row number upto which Pascal’s triangle has to be printed: “); int row = scanner.nextInt(); print(row); } }
Finding factorial of a Number in Java
The factorial of a number is defined is the product of natural numbers from one to that particular number. Mathematically, ... to use the BigInteger class which can handle arbitrarily large numbers which is discussed here. (link will be updated soon )
Matrix Addition and Subtraction
We will see how to perform matrix addition and subtraction in java. The two operations are similar except for a small differ ... of columns: 2 Enter first matrix 3 4 7 9 Enter second matrix 1 2 3 4 A + B = 4 6 10 13 A – B = 2 2 4 5 B – A = -2 -2 -4 -5
Decimal to Binary Conversion
The program for conversion of decimal to binary depends on the problem specification. It may be given that the decimal numbe ... mal = 0 and return “0” as the result. Given below is a sample output. Enter a number: 14 The binary representation is 1110
Sieve of Eratosthenes
The sieve of Eratosthenes is an efficient method for computing primes upto a certain number. We first look at the algorithm ... out of the for loop. Finally, we print the primes. Here is a sample run of the program. Enter a number: 13 2 3 5 7 11 13
Finbonacci Series
The following sequence of numbers is known as Fibonacci numbers or sequence or series. 0, 1, 1, 2, 3, 5, 8, 13, 21 …. To obt ... } else if (n == 1) { return 1; } else { return fibonacci(n – 1) + fibonacci(n – 2); } }}
Armstrong Numbers – Java Program
An Armstrong number is the one that equals the sum of its digits raised to the power of the number of digits in that number ... tart number: 1 Enter end number: 3479 List of Armstrong Numbers between 1 and 3479 : 1 2 3 4 5 6 7 8 9 153 370 371 407 1634
Factorial of large numbers using BigInteger
The factorial of numbers greater than or equal to 13 cannot be found using the program shown on this page due to overflow. T ... ue ‘1’. Here is a sample execution of the program. Enter a number: 34 Factorial is 295232799039604140847618609643520000000
Prime Numbers
A prime number has only two factors, namely one and itself. To determine whether a given number is prime, we need to check i ... Enter the first number number : 2 Enter the second number number : 10 List of prime numbers between 2 and 10 2 3 4 5 7 9
Matrix Multiplication
This article shows you how to write a matrix multiplication program in Java. A three level nested loop is used to perform th ... 3Enter number of columns in B: 3Enter matrix A1 3 42 5 6Enter matrix B1 5 62 5 41 1 1Product of A and B is11 24 2218 41 38
Towers of Hanoi
The ‘Towers of Hanoi’ is a classical problem used to illustrate the power of recursion. The puzzle goes as follows. There ... ample output with n = 3. Enter number of discs: 3 A -> C A -> B C -> B A -> C B -> A B -> C A -> C
Reversing a Number
We will see three different ways of reversing a number.
Contents
Reversing a Number using Mathematical Operations
Rever ... reversedString = stringBuffer.toString(); int reversedInt = Integer.parseInt(reversedString); return reversedInt; }
Converting a String to different Cases
In this article, we will see how to convert a given String to different cases using simple looping and methods of the String ... “Camel Case: ” + toCamelCase(inputString)); System.out.println(“Title Case: ” + toSentenceCase(inputString)); } }