answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nookie1986 [14]
2 years ago
12

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)
Computers and Technology
1 answer:
Aliun [14]2 years ago
7 0

Answer:

import java.util.Arrays;

public class swap{

   public static void main(String []args){

       int [] arr = {2,4};

       swapValues(arr);

   }

   public static void swapValues(int[] values){

       int temp;

       System.out.println(Arrays.toString(values));

       temp=values[0];

       values[0]=values[1];

       values[1] =temp;

       System.out.println(Arrays.toString(values));

   }

}

Explanation:

In the program above, we created the method swapValues that receives an array of integers as parameters. in the method definition, we created a temp variable that is used to swapp the element at index 0 and index 1. Java's Arrays.to string method is used to print the array before and after the swap.

You might be interested in
If there are 8 opcodes and 10 registers, a. What is the minimum number of bits required to represent the OPCODE? b. What is the
Nimfa-mama [501]

Answer:  

For 32 bits Instruction Format:

OPCODE   DR               SR1                   SR2      Unused bits

a) Minimum number of bits required to represent the OPCODE = 3 bits

There are 8 opcodes. Patterns required for these opcodes must be unique. For this purpose, take log base 2 of 8 and then ceil the result.

Ceil (log2 (8)) = 3

b) Minimum number of bits For Destination Register(DR) = 4 bits

There are 10 registers. For unique register values take log base 2 of 10 and then ceil the value.  4 bits are required for each register. Hence, DR, SR1 and SR2 all require 12 bits in all.  

Ceil (log2 (10)) = 4

c) Maximum number of UNUSED bits in Instruction encoding = 17 bits

Total number of bits used = bits used for registers + bits used for OPCODE  

     = 12 + 3 = 15  

Total  number of bits for instruction format = 32  

Maximum  No. of Unused bits = 32 – 15 = 17 bits  

OPCODE                DR              SR1             SR2              Unused bits

  3 bits              4 bits          4 bits           4 bits                17 bits

7 0
2 years ago
g Suppose the information content of a packet is the bit pattern 1110 0110 1001 1101 and an even parity scheme is being used. Wh
erma4kov [3.2K]

Answer: see description

Explanation:

first we accommodate the bit pattern in a matrix of 4x4 which is the minimum length checksum field, now with even parity two-dimensional scheme we need to complete this matrix by adding one row and one column by adding at the end of each row a 1 or a 0 to complete pairs of 1's:

we have

\left[\begin{array}{cccc}1&1&1&0\\0&1&1&0\\1&0&0&1\\1&1&0&1\end{array}\right]

so we complete with this, adding a row at the end which matches a pair number of 1's

\left[\begin{array}{ccccc}1&1&1&0&1\\0&1&1&0&0\\1&0&0&1&0\\1&1&0&1&1\\1&1&0&0&0\end{array}\right]

4 0
2 years ago
A(n) ____________________ is a named collection of stored data, instructions, or information and can contain text, images, video
Vanyuwa [196]
The answer in the blank is files for they exist in the computer that are responsible to hold or collect different types of application that could contribute in arranging them in order or showing classifications or simply storing them to put them in one place. This is essential to the computer for they are responsible in putting them in place and showing organization.
7 0
2 years ago
Read 2 more answers
Sharon is thinking about opening a bakery. She knows she wants to set her own hours, reduce her stress and make a profit. But sh
hodyreva [135]
Please provide complete details.
4 0
2 years ago
Complete the function to replace any period by an exclamation point. Ex: "Hello. I'm Miley. Nice to meet you." becomes:
vodomira [7]

Answer:

Here is the complete function:

void MakeSentenceExcited(char* sentenceText) {  // function that takes the text as parameter and replaces any period by an exclamation point in that text

int size = strlen(sentenceText);  //returns the length of sentenceText string and assigns it to size variable

char * ptr;  // character type pointer ptr

ptr = sentenceText;  // ptr points to the sentenceText string

for (int i=0; i<size; i++){  //iterates through the sentenceText string using i as an index

    if (sentenceText[i]=='.'){  // if the character at i-th index of sentenceText is a period

        sentenceText[i]='!'; } } } //places exclamation mark when it finds a period at i-th index of sentenceText

Explanation:

The program works as follows:

Suppose we have the string:

sentenceText = "Hello. I'm Miley. Nice to meet you."

The MakeSentenceExcited method takes this sentenceText as parameter

int size = strlen(sentenceText) this returns the length of sentenceText

The size of sentenceText is 35 as this string contains 35 characters

size =  35

Then a pointer ptr is declared which is set to point to sentenceText

for (int i=0; i<size; i++) loop works as follows:    

1st iteration:

i=0

i<size is true because i=0 and size = 35 so 0<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[0]=='.')

The first element of sentenceText is H

H is not a period sign so the statement inside if statement does not execute and value of i increments to 1. Now i = 1

2nd iteration:

i=1

i<size is true because i=1 and size = 35 so 1<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[1]=='.')

This is the second element of sentenceText i.e. e

e is not a period sign so the statement inside if statement does not execute and value of i increments to 1. Now i = 2

So at each iteration the if condition checks if the character at i-th index of string sentenceText is a period.

Now lets see a case where the element at i-th index is a period:

6th iteration:

i=5

i<size is true because i=5 and size = 35 so 5<35

So the body of loop executes:

 if (sentenceText[i]=='.') statement checks :

if (sentenceText[5]=='.')

This is the character at 5th index of sentenceText i.e. "."

So the if condition evaluates to true and the statement inside if part executes:

sentenceText[i]='!'; statement becomes:

sentenceText[5]='!'; this means that the character at 5th position of sentenceText string is assigned an exclamation mark.

So from above 6 iterations the result is:

Hello!

This loop continues to execute until all the characters of sentenceText are checked and when the value of i gets greater than or equal to the length of sentenceText then the loop breaks.

The screenshot of the program along with its output is attached.

6 0
1 year ago
Other questions:
  • A two-dimensional array can have elements of ________ data type(s).
    7·1 answer
  • Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
    6·1 answer
  • What is a typical grace period for a credit card...
    15·2 answers
  • When driving, your attention is __________.
    5·2 answers
  • Menus are attached to windows by calling the _____ method.
    8·1 answer
  • Suppose your company has decided that it needs to make certain busy servers faster. Processes in the workload spend 60% of their
    5·1 answer
  • Identify the correct language concept or term from the drop-down menu. A Programming Language is a language that physically runs
    12·2 answers
  • 1. Show that the three security services-confidentiality, integrity, and availabilty- are sufficient to deal with the threats of
    10·1 answer
  • Fill in the blanks to make the factorial function return the factorial of n. Then, print the first 10 factorials (from 0 to 9) w
    6·1 answer
  • CHALLENGE ACTIVITY 3.7.2: Type casting: Reading and adding values.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!