# Write a java program to print sum of two numbers

You should at your best on data-structures like an array, linked list, and string to clear any programming interview and believe me, you can not do this in one day or one week. In a programming interviewmany things matter apart from correct solution. Two of the most common examples of multi-dimensional arrays are two and three dimensional array, known as 2D and 3D array, anything above is rare. I have never seen 4 dimensional arrays, even 3D arrays are not that common.

Now question comes, when do use multi-dimensional array?

Any real life example? Another popular application of multi-dimensional arrays are in matrix manipulation. Similarly to represent 3x2 matrices you need 2 two dimensional array of one dimensional array of length 3. In other words, each row in two dimensional array is a one dimensional array. Java truly doesn't support multi-dimensional array but allows you to create and use array of any number of dimensional. Two dimensional array is actually an array of one dimensional array. Similar to one dimensional array, length of two dimensional array is also fixed. You can not change length of any arrayi.

## C++ program to Check Whether a Number can be Split into Sum of Two Prime Numbers

A 2x2 array can hold total 4 elements and they can be accessed using row and column index e. Just like normal array, index start at 0 and finishes at length How to Declare 2 Dimensional Array in Java If you know how to create one dimensional array and fact that multi-dimensional arrays are just array of array in Java, then creating a 2 dimensional array is very easy.

Instead of one bracket, you will use two e. You can define a 2D array in Java as follows: On the other hand second dimension is optional and even if you don't specify compiler will not complain, as shown below: Kumar In this example, you can see that salutation is a 2D array but its first row has 3 elements while second row has just one element.

You can access elements of a two dimensional array either by using both indexes or just one index. How to Initialize Two Dimensional Array in Java So far we have just declared and created the array, we haven't initialized them.

Which means all elements of array has their default values e. You can verify this by accessing first element of two dimensional array as multiples, which will print zero, as shown below.

## JAVA EXAMPLE PROGRAMS

Character array is bit tricky because if you print 0 as character it will print a null character and that's why I have used it's integer value by casting to int.

Now there are two ways to initialize a two dimensional array in Java, either by using array literal at the time of creation or by using nested for loop and going through each element. In next example we will learn how to loop through a two dimensional array, initialize each element and how to print a two dimensional array in Java.Taking Input from the User Wouldn't it be better if you could ask your friend to enter his own values and then display the sum of those two numbers?

There are several ways to do it in Java. But here, we shall look at one simple way by using the Scanner class. And then as usual we write the code for our class or program, similar to what. In this post, we will write two java programs, first java programs checks whether the specified number is positive or negative.

The second program takes the input number (entered by user) and checks whether it is positive or negative and displays the result.

C Programming language tutorial, Sample C programs, C++ Programs, Java Program, Interview Questions, C graphics programming, Data Structures, Binary Tree, Linked List, Stack, Queue, Header files, Design Patterns in Java, Triangle and Star pyramid pattern, Palindrome anagram Fibonacci programs, C puzzles.

## C programming Interview questions and answers: C program examples | Interview Complete List

5) There are multiple ways to define and initialize multidimensional array in Java, you can either initialise them using in the line of declaration or some time later using a nested for loop. Apr 06,  · Question Write a program in Java to find the Greatest Common Divisor (G.C.D.) of two numbers entered by the user: Java Program: To check whether a number is negative or positive Question 3: Write a program in Java to to check whether a number given by the user is negative or pfmlures.com: Mayank.

popular java interview programming test 1 2 3 years experience Java Programs asked in Interviews Frequently common most asked java programming java interview programs.

Java Program to Add Two Numbers