udaykumar1997

l

Apr 5th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. --------------------------
  2. Post Title 'OOC Assignment-5 Answers'
  3. Post by user 'Adusumilli-Uday-Kumar'
  4. Post encryped with secure 256-bit MD5 Encryption
  5. Post accesable only VIA link
  6. Post will Expire on '3-OCT-2017'
  7. --------------------------
  8.  
  9.  
  10.  
  11. Q1.
  12.  
  13. An array is a group of like-typed variables that are referred to by a common name. Arrays of any type can be created and may have one or more dimensions. A specific element in an array is accessed by its index. Arrays offer a convenient means of grouping related information.
  14.  
  15. i.
  16. One-Dimensional Arrays
  17. A one-dimensional array is, essentially, a list of like-typed variables. The general form of a one-dimensional array declaration is....
  18.  
  19. type var-name[ ];
  20.  
  21. Here, 'type' declares the base type of the array. The following declares an array named month_days with the type “array of int”....
  22.  
  23. int month_days[];
  24.  
  25. To link month_days with an actual, physical array of integers, you must allocate one using 'new' and assign it to 'month_days'. 'new' is a special operator that allocates memory. The general form of new as it applies to one-dimensional arrays appears as follows....
  26.  
  27. array-var = new type[size];
  28.  
  29. This example allocates a 12-element array of integers and links them to month_days....
  30.  
  31. month_days = new int[12];
  32.  
  33. Once you have allocated an array, you can access a specific element in the array by specifying its index within square brackets. All array indexes start at zero. For example, this statement assigns the value 28 to the second element of month_days....
  34.  
  35. month_days[1] = 28;
  36.  
  37. The next line displays the value stored at index 3....
  38.  
  39. System.out.println(month_days[3]);
  40.  
  41. ii. Multidimensional Arrays
  42. In Java, multidimensional arrays are actually arrays of arrays. To declare a multidimensional array variable, specify each additional
  43. index using another set of square brackets. For example, the following declares a two-dimensional array variable called twoD....
  44.  
  45. int twoD[][] = new int[4][5];
  46.  
  47. This allocates a 4 by 5 array and assigns it to twoD. Internally this matrix is implemented as an array of arrays of 'int'.
  48.  
  49.  
  50.  
  51. Q2.
  52.  
  53. Java provides a rich operator environment. Most of its operators can be divided into the following four groups: arithmetic, bitwise, relational, and logical. Java also defines some additional operators that handle certain special situations. A list of all the Operators include....
  54. 1. Basic Arithmetic Operators
  55. 2. Modulus Operators
  56. 3. Airthmatic Coumpound Assignment Operators
  57. 4. Increment and Decrement Operators
  58. 5. Bitwise Operators
  59. 6. Bitwise Logical Operators
  60. 7. Left Shift Operators
  61. 8. Right Shift Operators
  62. 9. Unsigned Right Operators
  63. 10. Bitwise Operator Compound Assignments
  64. 11. Relational Operators
  65. 12. Boolean Logical Operators
  66. 13. Short-Circuit Logical Operators
  67. 14. The Assignment Operator
  68. 15. The Ternary Operator
  69.  
  70.  
  71.  
  72. Q3.
  73.  
  74. i. The Unsigned Right Shift Operator
  75. the >> operator automatically fills the high-order bit with its previous contents each time a shift occurs. This preserves the sign of the value. However, sometimes this is undesirable. In these cases, you will generally want to shift a zero into the high-order bit no matter what its initial value was. This is known as an unsigned shift. To accomplish this, you will use Java’s unsigned, shift-right operator, >>>, which always shifts zeros into the high-order bit.
  76.  
  77. ii. The Right Shift
  78. The right shift operator, >>, shifts all of the bits in a value to the right a specified number of times. the >> moves all of the bits in the specified value to the right, by the number of bit positions specified to it's left.
  79. The following code fragment shifts the value 32 to the right by two positions, resulting in a being set to 8....
  80.  
  81. int a = 32;
  82. a = a >> 2; // a now contains 8
  83.  
  84. iii. Short-Circuit Logical Operators
  85. Java provides two interesting Boolean operators not found in many other computer languages. These are secondary versions of the Boolean AND and OR operators, and are known as short-circuit logical operators. For example, the following code fragment shows how you can take
  86. advantage of short-circuit logical evaluation to be sure that a division operation will be valid before evaluating it....
  87.  
  88. if ((denom != 0)
Add Comment
Please, Sign In to add comment