javawithus.com

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

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

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 )

Throwing Exceptions

We have seen till now how exceptions thrown by methods we invoke such as nextInt() can be caught. We shall now see how we ou ... rintln(“Exception caught”);     }    }} The output of this program would be Exception caught Prev : Nested try catch blocks

Privacy Policy for JavaWithUs

If you require any more information or have any questions about our privacy policy, please feel free to contact us by fillin ... e detailed information about cookie management with specific web browsers can be found at the browsers’ respective websites.

Creating objects and Calling Methods

Now that, we have coded a class, we will now use it to create different Student objects. We do all of this in a test class. ... ect: 98Marks in second subject: 100Marks in second subject: 96 Next : Get and Set MethodsPrev : The constituents of a Class

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

Searching and Sorting Arrays

An array is not just used to store elements but also access those stored values later on. We may also need to search for a p ... to learn about them, then refer to these pages on another site: Next : Array of objectsPrev : Processing arrays using loops

Terms And Conditions

Terms and Conditions for javawithus.com Introduction These Website Standard Terms and Conditions written on this webpage sha ... u submit to the non-exclusive jurisdiction of the state and federal courts located in sg for the resolution of any disputes.

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

Exception Handling

A program may not always reach to its end. It might be interrupted in several ways. A logical error in your program could cr ... have entered invalid dataEnter an integer: 347You entered 347 Next : Exception hierarchyPrev : Abstract classes and methods

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

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

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

Static Methods and Variables

Variables and methods of the Student class which we have written can be accessed only after creating an object of that class ... es from a static method. The Test class shows how static methods can be accessed using both the class name and method name.

Access Specifiers

We have quite often been using the access specifiers- public and private. We shall now see what these access specifiers actu ... owed not allowed public allowed allowed allowed allowed < unspecified > allowed not allowed allowed not allowed

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