What's new

Pa help for loops

TalyaJuan07

Honorary Poster
Joined
Jun 18, 2019
Posts
268
Reaction
56
Points
178
Pa help po dito baka alam niyo po kung paano diko po kasi gets

received_550437170394685.jpeg
 

Attachments

Java:
public class ArrayExample {
    public static void main(String[] args) {
        // Step 1: Create a universal set with 5 elements
        int[] universalSet = {1, 2, 3, 4, 5};
        
        // Step 2: Create an array with a variable name arrayDM using the universal set by passing specific values within the initializer
        int[] arrayDM = {1, 2, 3};
        
        // Step 3: Increase the size of arrayDM by creating a new array with a larger size
        int[] newArrayDM = new int[arrayDM.length + 1];
        
        // Step 4: Copy the existing elements to the new array
        for (int i = 0; i < arrayDM.length; i++) {
            newArrayDM[i] = arrayDM[i];
        }
        
        // Step 5: Add the new element at index 3
        newArrayDM[3] = 4;
        
        // Step 6: Set arrayDM to the new array
        arrayDM = newArrayDM;
        
        // Step 7: Get the value of arrayDM[0]
        int valueAtIndexZero = arrayDM[0];
        System.out.println("Value at index 0: " + valueAtIndexZero);
        
        // Step 8: Display all the values of arrayDM using for loop
        System.out.println("Values in arrayDM:");
        for (int i = 0; i < arrayDM.length; i++) {
            System.out.println(arrayDM[i]);
        }
    }
}

1676538876904.png
 

Attachments

Java:
public class ArrayExample {
    public static void main(String[] args) {
        // Step 1: Create a universal set with 5 elements
        int[] universalSet = {1, 2, 3, 4, 5};
       
        // Step 2: Create an array with a variable name arrayDM using the universal set by passing specific values within the initializer
        int[] arrayDM = {1, 2, 3};
       
        // Step 3: Increase the size of arrayDM by creating a new array with a larger size
        int[] newArrayDM = new int[arrayDM.length + 1];
       
        // Step 4: Copy the existing elements to the new array
        for (int i = 0; i < arrayDM.length; i++) {
            newArrayDM[i] = arrayDM[i];
        }
       
        // Step 5: Add the new element at index 3
        newArrayDM[3] = 4;
       
        // Step 6: Set arrayDM to the new array
        arrayDM = newArrayDM;
       
        // Step 7: Get the value of arrayDM[0]
        int valueAtIndexZero = arrayDM[0];
        System.out.println("Value at index 0: " + valueAtIndexZero);
       
        // Step 8: Display all the values of arrayDM using for loop
        System.out.println("Values in arrayDM:");
        for (int i = 0; i < arrayDM.length; i++) {
            System.out.println(arrayDM[i]);
        }
    }
}

View attachment 2521318
pano kaya pag c++ lods?
 
pano kaya pag c++ lods?
C++:
#include <iostream>
using namespace std;

int main() {
    // Step 1: Create a universal set with 5 elements
    int universalSet[] = {1, 2, 3, 4, 5};
    
    // Step 2: Create an array with a variable name arrayDM using the universal set by passing specific values within the initializer
    int arrayDM[] = {1, 2, 3};
    
    // Step 3: Insert an element on arrayDM
    arrayDM[3] = 4;
    
    // Step 4: Get the value of arrayDM[0]
    int valueAtIndexZero = arrayDM[0];
    cout << "Value at index 0: " << valueAtIndexZero << endl;
    
    // Step 5: Display all the values of arrayDM using for loop
    cout << "Values in arrayDM:" << endl;
    for (int i = 0; i < 4; i++) {
        cout << arrayDM[i] << endl;
    }
    
    return 0;
}

1676539823564.png
 

Attachments

pano kaya pag c++ lod

Java:
public class ArrayExample {
    public static void main(String[] args) {
        // Step 1: Create a universal set with 5 elements
        int[] universalSet = {1, 2, 3, 4, 5};
       
        // Step 2: Create an array with a variable name arrayDM using the universal set by passing specific values within the initializer
        int[] arrayDM = {1, 2, 3};
       
        // Step 3: Increase the size of arrayDM by creating a new array with a larger size
        int[] newArrayDM = new int[arrayDM.length + 1];
       
        // Step 4: Copy the existing elements to the new array
        for (int i = 0; i < arrayDM.length; i++) {
            newArrayDM[i] = arrayDM[i];
        }
       
        // Step 5: Add the new element at index 3
        newArrayDM[3] = 4;
       
        // Step 6: Set arrayDM to the new array
        arrayDM = newArrayDM;
       
        // Step 7: Get the value of arrayDM[0]
        int valueAtIndexZero = arrayDM[0];
        System.out.println("Value at index 0: " + valueAtIndexZero);
       
        // Step 8: Display all the values of arrayDM using for loop
        System.out.println("Values in arrayDM:");
        for (int i = 0; i < arrayDM.length; i++) {
            System.out.println(arrayDM[i]);
        }
    }
}

View attachment 2521318
Salamat bossing🥺
 

Similar threads

Back
Top