Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NUMBER 1
- //Declare
- String [] keys;
- //Instantiate or Allocate memory
- keys = new String [3];
- keys[0] = "Technological Institute";
- keys[1] = "of the Philippines";
- keys[2] = "Quezon City";
- System.out.println("Array element: " + keys[0]);
- System.out.println("Array element: " + keys[1]);
- System.out.println("Array element: " + keys[2]);
- }
- }
- NUMBER 2
- import javax.swing.JOptionPane;
- public class _2_ArrayClass2Exercise {
- public static void main(String[] args) {
- int arraySize;
- arraySize = Integer.parseInt(JOptionPane.showInputDialog("Enter array size: "));
- String [] keys = new String [arraySize];
- for (int counter = 0; counter < keys.length; counter++) {
- }
- for (int counter = 0; counter < keys.length; counter++) {
- keys [counter] = JOptionPane.showInputDialog("Enter elements in String: ");
- }
- for (int counter = 0; counter < keys.length; counter++) {
- JOptionPane.showMessageDialog(null, keys[counter]);
- }
- }
- }
- NUMBER 3
- public class _3_ArrayClass3Exercise {
- byte arraySize;
- String keys;
- //Constructor
- public _3_ArrayClass3Exercise(byte arraySize) {
- this.keys = keys;
- }
- public _3_ArrayClass3Exercise(String keys) {
- this.keys = keys;
- }
- public void setArraySize(byte arraySize) {
- this.arraySize = arraySize;
- }
- public String getKeys() {
- return keys;
- }
- public void setKeys(String keys) {
- this.keys = keys;
- }
- public byte getArraySize() {
- return arraySize;
- }
- }
- NUMBER 4
- import javax.swing.*;
- public class _4_ArrayClass4RunnerExercise {
- public static void main(String[] args) {
- byte arraySize;
- arraySize = Byte.parseByte(JOptionPane.showInputDialog ("Enter array Size: "));
- _3_ArrayClass3Exercise array1 = new _3_ArrayClass3Exercise(arraySize);
- _3_ArrayClass3Exercise [] array2 = new _3_ArrayClass3Exercise[array1.getArraySize()];
- for (int ctr = 0; ctr < array2.length; ctr++) {
- array2[ctr] = new _3_ArrayClass3Exercise(JOptionPane.showInputDialog("Enter Strings: "));
- }
- for (int ctr = 0; ctr < array2.length; ctr++) {
- JOptionPane.showMessageDialog(null, array2[ctr].getKeys());
- }
- }
- }
- NUMBER 5
- public class _5_ArrayClass5Exercise {
- double arraySize;
- String message;
- int keys;
- //Constructor
- public _5_ArrayClass5Exercise(double arraySize) {
- this.arraySize = arraySize;
- }
- public _5_ArrayClass5Exercise(int keys, String message) {
- this.keys = keys;
- this.message = message;
- }
- public double getArraySize() {
- return arraySize;
- }
- public void setArraySize(double arraySize) {
- this.arraySize = arraySize;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public int getKeys() {
- return keys;
- }
- public void setKeys(int keys) {
- this.keys = keys;
- }
- }
- NUMBER 6
- import javax.swing.*;
- public class _6_ArrayClassRunnerExercise {
- public static void main(String[] args) {
- double arraysize;
- arraysize = Double.parseDouble(JOptionPane.showInputDialog ("Enter Array Size: "));
- _5_ArrayClass5Exercise array1 = new _5_ArrayClass5Exercise(arraysize);
- _5_ArrayClass5Exercise [] array2 = new _5_ArrayClass5Exercise[(int) array1.getArraySize()];
- for (int ctr = 0; ctr < array2.length; ctr++) {
- array2[ctr]= new _5_ArrayClass5Exercise(Integer.parseInt(JOptionPane.showInputDialog("Enter keys: ")), JOptionPane.showInputDialog ("Enter message: "));
- }
- for (int ctr = 0; ctr < array2.length; ctr++) {
- JOptionPane.showMessageDialog(null, array2[ctr].getKeys() +" "+ array2[ctr].getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement