Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /**
  2.  * Exercise 1
  3.  * Define a class named Node with the appopriate fields and constructors. Write a Java application
  4.  * to construct TWO(2) object nodes with integer values of 4 and 7. Print the values and memory
  5.  * addresses of the nodes
  6.  *
  7.  * @author MUHAMMAD AZRI BIN JASNI @ ABDUL RANI
  8.  * @version 10 OCTOBER 2012
  9.  */
  10. import java.util.*;//Scanner
  11. public class exercise1
  12. {
  13.     public static void main (String [] args)
  14.     {
  15.         Scanner sc = new Scanner(System.in);
  16.        
  17.         Node objNode1 = new Node();
  18.         Node objNode2 = new Node();
  19.         int input;
  20.        
  21.         System.out.print("Enter object node 1: ");
  22.         input = sc.nextInt();
  23.         objNode1 = new Node(input);
  24.        
  25.         System.out.print("Enter object node 2: ");
  26.         input = sc.nextInt();
  27.         objNode2 = new Node(input,objNode1);
  28.        
  29.         //display
  30.         System.out.println("Data objNode1: "+ objNode1.getData() +"\nLink objNode1: "+objNode1.getLink());
  31.         System.out.println("Data objNode2: "+ objNode2.getData() +"\nLink objNode2: "+objNode2.getLink());
  32.        
  33.         sc.close();
  34.     }
  35. }