004-004-007

Array Value Swap

Easy

Problem Description

Array Value Swap

Learning Objective: Understand how to swap two elements using array assignment operations

Overview

Create a program that initializes an integer array with 3 elements and swaps the first and last elements.

Specifications

  • Initialize an int[] array with {10, 20, 30}
  • Print the array contents before swapping
  • Swap the elements at index 0 and index 2 using a temporary variable
  • Print the array contents after swapping

Output Format

Before: 10 20 30
After: 30 20 10

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?