Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.80 KB | None | 0 0
  1. NUMBER 1
  2.  
  3. //Declare
  4. String [] keys;
  5.  
  6. //Instantiate or Allocate memory
  7. keys = new String [3];
  8.  
  9. keys[0] = "Technological Institute";
  10. keys[1] = "of the Philippines";
  11. keys[2] = "Quezon City";
  12.  
  13. System.out.println("Array element: " + keys[0]);
  14. System.out.println("Array element: " + keys[1]);
  15. System.out.println("Array element: " + keys[2]);
  16.  
  17. }
  18.  
  19. }
  20.  
  21. NUMBER 2
  22.  
  23. import javax.swing.JOptionPane;
  24.  
  25. public class _2_ArrayClass2Exercise {
  26.  
  27. public static void main(String[] args) {
  28. int arraySize;
  29.  
  30. arraySize = Integer.parseInt(JOptionPane.showInputDialog("Enter array size: "));
  31.  
  32. String [] keys = new String [arraySize];
  33.  
  34. for (int counter = 0; counter < keys.length; counter++) {
  35.  
  36. }
  37. for (int counter = 0; counter < keys.length; counter++) {
  38. keys [counter] = JOptionPane.showInputDialog("Enter elements in String: ");
  39. }
  40. for (int counter = 0; counter < keys.length; counter++) {
  41. JOptionPane.showMessageDialog(null, keys[counter]);
  42. }
  43.  
  44. }
  45.  
  46. }
  47.  
  48. NUMBER 3
  49.  
  50. public class _3_ArrayClass3Exercise {
  51.  
  52. byte arraySize;
  53. String keys;
  54.  
  55. //Constructor
  56. public _3_ArrayClass3Exercise(byte arraySize) {
  57. this.keys = keys;
  58. }
  59.  
  60. public _3_ArrayClass3Exercise(String keys) {
  61. this.keys = keys;
  62. }
  63.  
  64. public void setArraySize(byte arraySize) {
  65. this.arraySize = arraySize;
  66. }
  67.  
  68. public String getKeys() {
  69. return keys;
  70. }
  71.  
  72. public void setKeys(String keys) {
  73. this.keys = keys;
  74. }
  75.  
  76. public byte getArraySize() {
  77. return arraySize;
  78. }
  79.  
  80. }
  81.  
  82. NUMBER 4
  83.  
  84. import javax.swing.*;
  85.  
  86. public class _4_ArrayClass4RunnerExercise {
  87.  
  88. public static void main(String[] args) {
  89.  
  90. byte arraySize;
  91. arraySize = Byte.parseByte(JOptionPane.showInputDialog ("Enter array Size: "));
  92.  
  93. _3_ArrayClass3Exercise array1 = new _3_ArrayClass3Exercise(arraySize);
  94.  
  95. _3_ArrayClass3Exercise [] array2 = new _3_ArrayClass3Exercise[array1.getArraySize()];
  96.  
  97. for (int ctr = 0; ctr < array2.length; ctr++) {
  98. array2[ctr] = new _3_ArrayClass3Exercise(JOptionPane.showInputDialog("Enter Strings: "));
  99.  
  100. }
  101. for (int ctr = 0; ctr < array2.length; ctr++) {
  102. JOptionPane.showMessageDialog(null, array2[ctr].getKeys());
  103. }
  104. }
  105.  
  106.  
  107.  
  108. }
  109.  
  110. NUMBER 5
  111.  
  112. public class _5_ArrayClass5Exercise {
  113. double arraySize;
  114. String message;
  115. int keys;
  116.  
  117. //Constructor
  118. public _5_ArrayClass5Exercise(double arraySize) {
  119. this.arraySize = arraySize;
  120. }
  121.  
  122. public _5_ArrayClass5Exercise(int keys, String message) {
  123. this.keys = keys;
  124. this.message = message;
  125.  
  126. }
  127.  
  128. public double getArraySize() {
  129. return arraySize;
  130. }
  131. public void setArraySize(double arraySize) {
  132. this.arraySize = arraySize;
  133. }
  134. public String getMessage() {
  135. return message;
  136. }
  137. public void setMessage(String message) {
  138. this.message = message;
  139. }
  140. public int getKeys() {
  141. return keys;
  142. }
  143. public void setKeys(int keys) {
  144. this.keys = keys;
  145. }
  146. }
  147.  
  148. NUMBER 6
  149.  
  150. import javax.swing.*;
  151.  
  152. public class _6_ArrayClassRunnerExercise {
  153.  
  154. public static void main(String[] args) {
  155. double arraysize;
  156. arraysize = Double.parseDouble(JOptionPane.showInputDialog ("Enter Array Size: "));
  157.  
  158. _5_ArrayClass5Exercise array1 = new _5_ArrayClass5Exercise(arraysize);
  159.  
  160. _5_ArrayClass5Exercise [] array2 = new _5_ArrayClass5Exercise[(int) array1.getArraySize()];
  161.  
  162. for (int ctr = 0; ctr < array2.length; ctr++) {
  163. array2[ctr]= new _5_ArrayClass5Exercise(Integer.parseInt(JOptionPane.showInputDialog("Enter keys: ")), JOptionPane.showInputDialog ("Enter message: "));
  164. }
  165. for (int ctr = 0; ctr < array2.length; ctr++) {
  166. JOptionPane.showMessageDialog(null, array2[ctr].getKeys() +" "+ array2[ctr].getMessage());
  167. }
  168. }
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement