1answer.
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
Blababa [14]
3 years ago
12

A code segment will be used to swap the values of the variables a and b using the temporary variable temp. Which of the followin

g code segments correctly swaps the values of a and b?
a) a to b, temp to a, b to temp
b) temp to a, a to b, b to temp
c) temp to a, a to temp, a to b
d) temp to a, b to temp, a to b
Computers and Technology
1 answer:
shtirl [24]3 years ago
4 0

Answer:

Option (b)

Explanation:

These are the right statements but the correct order would be :

temp=b;

b=a;

a=temp;

Value of b will be stored in temp variables and then value of a will be stored in b and afterwards value of temp variable to a. This is how value of a &b will be swapped. Swapping is needed in various codes many times. For example - while sorting an array, while reversing a string,etc.

You might be interested in
What are the advantages of AI?????
mr Goodwill [35]
AI is a technology that can do thing that humans are doing. So in future humans don’t have to these AI will do it for us.
4 0
4 years ago
Does an android tablet have a hard drive
Kisachek [45]
No, it uses flash menory
3 0
4 years ago
____ is the use of networking technology to provide medical information and services.
Cerrena [4.2K]
Answer: WebMD

WebMD, with the URL https://www.webmd.com, provides credible health and medical information on the web.
3 0
3 years ago
Write a program that performs a simulation to estimate the probability of rolling five of a kind in a single toss of five six-si
VikaD [51]

Answer:

import random

def probability_five_of_a_kind(num_trials):

   sums = 0

   for _ in range(num_trials):

       roll_1 = random.randrange(1,6, 1)

       roll_2 = random.randrange(1,6, 1)

       roll_3 = random.randrange(1,6, 1)

       roll_4 = random.randrange(1,6, 1)

       roll_5 = random.randrange(1,6, 1)

       collection = roll_1 + roll_2 + roll_3 + roll_4 + roll_5

       if collection == 5:

           sums += 1

   prob = round(sums/7776, 8)

   print(f"The probability_five_of_a_kind is {prob}")

   

probability_five_of_a_kind(100)

probability_five_of_a_kind(10000)

probability_five_of_a_kind(1000000)

Explanation:

The random package of the python language is used to select an integer value from the range of one to six representing the sides of a die. All six rolls are randomized and the sum. If the sum is equal to 5, the sums counter is incremented. At the end of the loop, the sum is divided by the five dices events (which is 6^5 = 7776).

8 0
3 years ago
The following code does not work as intended. It is meant to input two test grades and return the average in decimal format:
vredina [299]

Answer:

Type casting error

Explanation:

Logically, the program is correct and it is expected to return the average value. However, test1 and test2 are int values and when you applies any algebraic expression on Int, it will result into Int.

So, in this part (test1 + test2 )/2, two integers are adding and the final result is still an integer and this part will act as an integer even if you multiple or divide with any external number.

For example,

test1 = 4

test2 = 5

test1 + test2 = 9

Now, if you divide it by 2, it will still react as an integer portion. So, 9/2 would result in 4 instead of 4.5. All the calculation is done on the right side before assigning it to a double variable. Therefore, the double variable is still getting the int value and your program is not working correctly.

The solution is to typecast the "(test1 + test2 )/2" portion to double using Double.valueOf(test1 + test2)/2 ;

I have also attached the working code below.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

 System.out.println("Hello World");

 Scanner scan = new Scanner (System.in);

 int test1 = scan.nextInt();

       int test2 = scan.nextInt();

       double average = Double.valueOf(test1 + test2)/2 ;

       System.out.println("Answer: " + average);

}

}

4 0
4 years ago
Other questions:
  • Janet is testing the effectiveness of four different plant foods. She plants four identical seeds in four identical pots, supply
    6·2 answers
  • Modify the list according to the following: append the smallest value at the end of the list when all numbers in the list are ne
    14·1 answer
  • HURRY!! Ill give brainily and 25 points. Describe how Scent is related to the culture and historical period when it was created.
    15·1 answer
  • True or false: within a database, fields can be added, deleted and edited but never moved.
    11·1 answer
  • Enter a word: Good<br> Enter a word: morning<br> Good morning
    8·2 answers
  • - What are the different types of clients?
    12·1 answer
  • Wrtie down some containerization technology.
    11·1 answer
  • Why must a mobile application be easily customized and personalized?
    14·2 answers
  • What is a fire wall and how does it work
    14·1 answer
  • Explain how mobile phone production could be more sustainable​
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!