🔒 Closed Pa help for loops

Status
Not open for further replies.

TalyaJuan07

Honorary Poster
Pa help po dito baka alam niyo po kung paano diko po kasi gets

received_550437170394685.webp
 
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.webp
 
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.webp
 
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🥺
 
Status
Not open for further replies.

Similar threads

About this Thread

  • 4
    Replies
  • 491
    Views
  • 3
    Participants
Last reply from:
TalyaJuan07

Online now

Members online
839
Guests online
913
Total visitors
1,752

Forum statistics

Threads
2,276,095
Posts
28,967,564
Members
1,231,118
Latest member
czardinas
Back
Top