Write a program whose input is two integers and whose output is the two integers swapped. Place the values in an array, where x is position 0 and y is position 1.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter10: Classes And Data Abstraction
Section: Chapter Questions
Problem 22PE
icon
Related questions
Question
Using java help me solve this lab assignment
Write a program whose input is two integers and whose output is the two integers swapped. Place the values in an array, where x is
position 0 and y is position 1.
Ex: If the input is:
3 8
then the output is:
8 3
Your program must define and call a method:
public static void swapValues (int[] values)
354532.2042412.qx3zay7
LAB
6.28.1: LAB: Swapping variables
0/10
ACTIVITY
LabProgram.java
Load default template..
9.
System.out.println(arrays.toString(values));
10
11
temp=values[0];
12
13
values[0]=values[1];
14
15
values[1] =temp;
16
17
System.out.println(arrays.toString(values));
18
19
public static void main(String[] args) {
int [] arr = {2,4};
20
21
22
swapValues (arr);
23
24
25 }
Run your program as often as you'd like, before submitting for grading. Below, type any needed
input values in the first box, then click Run program and observe the program's output in the
Develop mode
Submit mode
second box.
Fz
近
Transcribed Image Text:Write a program whose input is two integers and whose output is the two integers swapped. Place the values in an array, where x is position 0 and y is position 1. Ex: If the input is: 3 8 then the output is: 8 3 Your program must define and call a method: public static void swapValues (int[] values) 354532.2042412.qx3zay7 LAB 6.28.1: LAB: Swapping variables 0/10 ACTIVITY LabProgram.java Load default template.. 9. System.out.println(arrays.toString(values)); 10 11 temp=values[0]; 12 13 values[0]=values[1]; 14 15 values[1] =temp; 16 17 System.out.println(arrays.toString(values)); 18 19 public static void main(String[] args) { int [] arr = {2,4}; 20 21 22 swapValues (arr); 23 24 25 } Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the Develop mode Submit mode second box. Fz 近
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Arrays
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning