codescracker


java

Java Program to Add Two Numbers using Pointers



« Previous Program Next Program »


Add two Numbers using Pointer

To add two numbers using pointer in Java Programming, you have to ask to the user to enter the two number to add them using pointer and display the summation result on the output screen:

Java Programming Code to Add Two Numbers using Pointer

Following Java Program ask to the user to enter the two number and will find the summation of the two entered numbers using pointer, and display the addition result on the screen:

/* Java Program Example - Add Two Numbers using Pointer */
		
import java.util.Scanner;


class IntObj
{
    public int value;
}
public class JavaProgram
{
   public static void main(String args[])
   {
       int num1, num2, sum=0;
       IntObj ptr1;
       IntObj ptr2;
       Scanner scan = new Scanner(System.in);
	   
       System.out.print("Enter Two Number : ");
       num1 = scan.nextInt();
       num2 = scan.nextInt();
	   
       ptr1 = new IntObj();
       ptr2 = new IntObj();
       ptr1.value = num1;
       ptr2.value = num2;
	   
       sum = ptr1.value + ptr2.value;
	   
       System.out.print("Sum of the Two Number is " +sum);
   }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program add two numbers using pointer

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test