A common programming operation is to swap or exchange the values of two variables. If the value of x is currently 19 and the value of y is 42, swapping them will make x into 42 and y into 19. Write a program named Swap.java that allows the user to enter two int values. The program should store those values into variables and then swap the variables. Print the values of both variables before and after the swap. You will receive full credit as long as your solution works, but try to do this using as few variables as possible

Answers

Answer 1

Answer:

import java.util.Scanner;

public class Swap

{

public static void main(String[] args) {

   

    Scanner input = new Scanner(System.in);

    int x, y, t;

 System.out.print("Enter the first variable: ");

 x = input.nextInt();

 System.out.print("Enter the second variable: ");

 y = input.nextInt();

 

 System.out.printf("Values before the swap -> x = %d, y = %d\n", x, y);

 

 t = x;

 x = y;

 y = t;

 

 System.out.printf("Values after the swap -> x = %d, y = %d\n", x, y);

}

}

Explanation:

Import the Scanner class

Create a Scanner object to be able to get input from the user

Declare the variables, x, y, and t - the variable t will be used as temporary variable that will hold the value of x

Ask the user to enter the first and second variables

Print the values before swap

Assign the value of x to the t

Assign the value of y to the x (Now, x will have the value of y)

Assign the value of the t to the y (Since t holds the value of x, y will have the value of x)

Print the values after the swap


Related Questions

Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording miles driven and gallons used for each tankful. Develop a sentinel-controlled-repetition script that prompts the user to input the miles driven and gallons used for each tankful. The script should calculate and display the miles per gallon obtained for each tankful. After processing all input information, the script should calculate and display the combined miles per gallon obtained for all tankfuls (that is, total miles driven divided by total gallons used).
Enter the gallons used (-1 to end): 128
Enter the miles driven: 287 The miles/gallon for this tank was 22.421875
Enter the gallons used (-1 to end): 10.3
Enter the miles driven: 200 The miles/gallon for this tank was 19.417475
Enter the gallons used (-1 to end): 5
Enter the miles driven: 120 The miles/gallon for this tank was 24.000000
Enter the gallons used (-1 to end): -1 The overall average miles/gallon was 21. 601423

Answers

Answer:

In Python:

gals= float(input("Enter the gallons used (-1 to end): "))

miles = float(input("Enter the miles driven: "))

mileage = 0.0

count = 0

while not (gals == -1):

   count += 1

   mileage +=(miles/gals)

   print("The miles/gallon for this tank was "+str(round(miles/gals,6)))

   gals= float(input("Enter the gallons used (-1 to end): "))

   miles = float(input("Enter the miles driven: "))

print("The overall average miles/gallon was "+str(round(mileage/count,6)))

Explanation:

#This prompts the user for the number of gallons used

gals= float(input("Enter the gallons used (-1 to end): "))

#This prompts the user for miles driven

miles = float(input("Miles driven: "))

#This initializes the mileage to 0

mileage = 0.0

#This initializes the count of vehicles to 0

count = 0

#The following is repeated until input for gallons is -1

while not (gals == -1):

#The count of vehicles is increased by 1

   count += 1

#The total mileage for all cars is calculated

   mileage +=(miles/gals)

#This prints the mileage for that particular vehicle

   print("The miles/gallon for this tank was "+str(round(miles/gals,6)))

#This prompts the user for the number of gallons used

   gals= float(input("Enter the gallons used (-1 to end): "))

#This prompts the user for miles driven

   miles = float(input("Miles driven: "))

#This calculates and prints the overall average mileage  

print("The overall average miles/gallon was "+str(round(mileage/count,6)))

3. What workplace hazards can be found on picture A?

4-5. Describe the workplace A and B, What are their differences​

Answers

Answer:

Hakdog

Explanation:

kase hakdog ka kainin mo tite ko

Suppose that an intermixed sequence of push and pop operations are performed on a LIFO stack. The pushes push the numbers 0 through 9 in order; the pops print out the return value. For example"push(0); pop(); push(1)" and "push(0); push(1); pop()" are possible, but "push(1); push(0); pop()" is not possible, because 1 and 0 are out of order. Which of the following output sequence(s) could occur? Select all that are possible.
a) 12543 609 8 7 0
b) 01564 37928
c) 6543210789
d) 02416 75983
e) 46 8 75 32 901

Answers

Answer:

b) 01564 37928

e) 26 8 75 32 901

Explanation:

Pushes and pulls are the computer operations which enable the user to perform numerical tasks. The input commands are interpreted by the computer software and these tasks are converted into numeric values to generate output.

Write an algorithm to show whether a given number is even or odd.

Answers

Answer:

int num = Console.ReadInt("Please enter a number");

if(num%2 == 0) {

Console.WriteLine("Number is even");

} else {

Console.WriteLine("Number is odd");

Explanation:

Who manages the team’s work during a sprint?
a) Scrum master manages the people so they can complete the work
b) The team manages the work by self organization
c) Product owner manages the work
d) Delivery manger manages the work

Answers

Answer:

d) delivery manger manages the work

Explanation:

sana po makatulong ako daghay salamat sayo emo

Complete the sentence. Use a ___ ___ (2 words) to find a website's URL based on keywords you specify.​

Answers

Answer: Search engine

Explanation:

If you need to find out the URL of a website that can help you with a particular service needed, you can use a search engine such as G-oogle or Duck-duckgo to find the relevant websites. You type in keyword/s and the search engine will look for websites associated with the word/s.

The links to be websites will be displayed and clicking on them will take you to the website.

10. Select the correct answer.
Thomas has signed a deal with a production house that allows them to use his images on their website. What is required that permits the usage of images for commercial or editorial purposes?
A.
copyright
B.
licensing
C.
permit
D.
public domain
E.
fair use

Answers

b) licensing because they are giving Thomas permission to use the images
B is the correct answer .!!!!!

Type the correct answer in the box. Spell all words correctly.
John wants to use graphical elements on his web page. Which image formats should he use to keep the file size manageable?
John should use
formats to keep the file size manageable.

Answers

Answer:

JPEG or PNG but mostly JPEG

Explanation:

JPEG – JPEG is the best option for photographs and other images displaying a huge variety of colors. They can also be compressed, sacrificing quality for a reduction in file size.

PNG – PNGs win for graphics, drawings, text, and some screenshots. They also support transparency, unlike JPEGs. This format uses lossless compression, which results in higher quality but also bigger files.

The image formats should he use to keep the file size manageable is JPEG or PNG however commonly JPEG.

What is JPEG format?

JPEG is the high-satisfactory choice for pics and different pix showing a massive sort of colors. They also can be compressed, sacrificing high-satisfactory for a discount in report size.

PNG PNGs win for graphics, drawings, text, and a few screenshots. They additionally help transparency, not like JPEGs. This layout makes use of lossless compression, which leads to better high-satisfactory but additionally larger files.

Read more about the image formats:

https://brainly.com/question/26733261

#SPJ2

Now, it’s time for you to begin coding your text-based adventure game!Starting at the top, convert each line of your pseudocode from your Coding Log into a line of Python code.Make sure to use the correct syntax and indentation. If you decide to challenge yourself and use functions, be sure to include the correct function calls.Your code should include at least two loops—one while loop and one for loop.Run and test your code in parts as you go. Follow the iterative process of coding and revising. It may be helpful to apply this process to each part of your game (Intro, Part 1, Part 2, and Part 3).Make the following improvements to your game:If the user types in a slightly different word than you expect, you don’t want your game to crash! Use lists to gain a better understanding of the input that users give. Refer back to Unit 1 for more information on lists. Here is an example:if choice in [“set a trap”, “set trap”, “trap”, “make a trap”, “make trap”]Your list won’t work if the user capitalizes any letter because the Interpreter won’t recognize a match between the same lowercase and uppercase letter. To convert the user input to all lowercase, use the lower function:if choice.lower() in [“set a trap”, “set trap”, “trap”, “make a trap”, “make trap”]Go through and make sure all of your inputs are converted to lowercase.Share the link to your Python code with your teacher in REPL.it by clicking on the share button and copying the link. Also, submit your pseudocode.

Answers

Answer:

When I finish I will send answer.

Explanation:

The coding exercise tests the ability to code using Python. It is important to note that all the indentation rules must be observed while running this code to prevent Indentation Error.



What is the code for the above exercise?

The code for the above exercise is given as follows:


def start():

# give some prompts.

 print("\nYou are standing in a dark room.")

print("There is a door to your left and right, which one do you take? (l or r)")

# convert the player's input() to lower_case

answer = input(">").lower()

if "l" in answer:

# if player typed "left" or "l" lead him to bear_room()

 bear_room()

elif "r" in answer:

# else if player typed "right" or "r" lead him to monster_room()

 monster_room()

else:

# else call game_over() function with the "reason" argument

 game_over("Don't you know how to type something properly?")

# start the game

start()


Learn more about python at:
https://brainly.com/question/26497128

#SPJ2

Mad Libs are activities that have a person provide various words, which are then used to complete a short story in unexpected (and hopefully funny) ways.
Write a program that takes a string and integer as input, and outputs a sentence using those items as below. The program repeats until the input string is quit.
Ex: If the input is:
apples 5
shoes 2
quito 0
the output is
Eating 5 apples a day keeps the doctor away.
Eating 2 shoes a day keeps the doctor away.
Note: This is a lab from a previous chapter that now requires the use of a loop. LB 334 1 LAB Mad Lib-loops main.cpp Load default template.
1 #include
2 #include
3 using namespace std;
4
5 int main()
6
7 {
8 return;
9
10

Answers

Answer:

Following are the code to this question:

#include <iostream>//header file

#include <string>//header file

using namespace std;

int main() //main method

{

   string item;//defining a string variable

   int n;//defining integer variable

   while(cin >>n >>item)//defining while loop to input value  

   {

       if(item == "quito" && n == 0)//use if block to check input value  

       {

           break;//use break keyword

       }

       cout << "Eating " << n << " " << item << " a day keeps the doctor away." << endl;//print input value with the message

   }

   return 0;

}

Output:

Please find the attached file.

Explanation:

In this code, inside the main method one string variable and one integer variable "item, n" is defined, that uses the while loop for input the value and uses the if block that checks string value is equal to "quito" and n value is equal to "0" it breaks the loop, and print the value with the message.

Every home or organization with Internet access has an ISP.
Question 29 options:
True
False

Answers

true ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎ ‎

What would a bar graph best be used for? State why and give 2-3 examples of things you could demonstrate with a bar graph

Answers

Answer:

A bar graph is used to compare facts.

For example:

A group of people's favorite movie.

A group of people's favorite fruit.

Consider the following method, inCommon, which takes two Integer ArrayList parameters. The method returns true if the same integer value appears in both lists at least one time, and false otherwise.

public static boolean inCommon(ArrayList a, ArrayList b)
{
for (int i = 0; i < a.size(); i++)
{
for (int j = 0; j < b.size(); j++) // Line 5
{
if (a.get(i).equals(b.get(j)))
{
return true;
}
}
}
return false;
}

Which of the following best explains the impact to the inCommon method when line 5 is replaced by for (int j = b.size() - 1; j > 0; j--) ?

a. The change has no impact on the behavior of the method.
b. After the change, the method will never check the first element in list b.
c. After the change, the method will never check the last element in list b.
d. After the change, the method will never check the first and the last elements in list b.
e. The change will cause the method to throw an IndexOutOfBounds exception.

Answers

Answer:

b. After the change, the method will never check the first element in list b.

Explanation:

After changing the code on line 5 with the one in the question the method will never check the first element in list b. This is because by changing the code you are telling the method to run for every element in list b starting from the last element and moving backward. Since the second argument is j > 0, once j is equal to 0 it will not run the method since it would give a False on the argument and therefore, will never run the method for the element in position 0 (first element in the list)

How can we display outputs of DIR one screenful at a time? There are at least two different ways, and either one is acceptable.

Answers

Answer:

DIR has a /p option to paginate any output.

dir /p

Will give you one screen length at a time.

I believe you can use that simultaneously with /w if you want to fit more file names on the screen, at the loss of additional data like file size, type, etc.

Given the waveform below, derive the output waveform (Q) for the respective devices. All outputs start at RESET (Q = 0) state


a) S-R latch assuming A = S and B = R.
b) Gated D latch assuming C = EN and B = D.
c) Negative Edge-triggered D Flip-flop assuming C = CLK and A = D.
d) Positive Edge-triggered J-K Flip-flop assuming C = CLK, A = J, and B = K.

Answers

The answer is b but I’m not sure

It's important to understand that even information systems that do not use computers
have a software resource component. State the two (2) types of software resources
with an example for each type to support your answers.

Answers

Answer:

yes I am not sure if you have any questions or concerns please visit the plug-in settings to determine how attachments are handled the situation in the measurements of the season my dear friend I am not sure if you can send you a great day to day basis of

You want to make access to files easier for your users. Currently, files are stored on several NTFS volumes such as the C:, D:, and E: drives. You want users to be able to access all files by specifying only the C: drive so they don't have to remember which drive letter to use. For example, if the accounting files are stored on the D: drive, users should be able to access them using C:\accounting. What can you do?

Answers

Answer:

volume mount points

Explanation:

The best thing to do would be to use volume mount points. This is a feature that allows you to mount/target (from a single partition) another folder or storage disk that is connected to the system. This will easily allow the user in this scenario to access the different files located in the D: and E: drive from the C:\ drive itself. Without having to go and find each file in their own separate physical drive on the computer.

Is a NAS just a collection of hard drives or a computer

Answers

Answer:

NAS systems are networked appliances that contain one or more storage drives, often arranged into logical, redundant storage containers or RAID.

#include
main()
{
int i, n=10, rem, inc=0;
scanf("%d",&n);
for(i=1; i =3)
inc++;
else;
inc--;
}
printf("Final Value=\n",inc);
}
SOLVE THIS PROGRAM...

Answers

Answer:inpossible !889

Explanation: I npossible !889

.............................................is the vertical distance between successive lines of the text​

Answers

Answer:

Line spacing is the vertical distance between successive lines of the text​.

Explanation:

Hope this helps you. :)

Why is sequencing important?

A. It allows the programmer to test the code.
B. It allows the user to understand the code.
C. It ensures the program works correctly.
D. It makes sure the code is easy to understand.

Answers

Answer:

c i think but if not go with d

Answer:

C

Explanation:

It ensures the program works correctly

hope it helps!

Help ASAP please This is a skills lab simulation for college, it’s on Microsoft word is there a keyboard shortcut or something on Ribbon tab to remove widow/orphan control option

Answers

Answer:

down right corner

Explanation:

next to the time

Retype each statement to follow the good practice of a single space around operators.

a. tot = num1+num2+2;
b. numBalls=numBalls+1;
c. numEntries = (userVal+1)*2;

Answers

Answer:

a. tot = num1 + num2 + 2;

b. numBalls = numBalls + 1;

c. numEntries = (userVal + 1) * 2;

Explanation:

Given

(a), (b) and (c)

Require:

Rewrite

There isn't much to do or explain; All you need to do is include single space between the operands and opcodes

So:

tot = num1+num2+2;   becomes tot = num1 + num2 + 2;

numBalls=numBalls+1; becomes numBalls = numBalls + 1;

numEntries = (userVal+1)*2; becomes  numEntries = (userVal + 1) * 2;

The difference in both statements is the inclusion of single line spacing.

help me in computer

no spam i will report wrong answer​

Answers

In the computar process it has to be done in a blind fold

Security attacks are classified as either passive or aggressive. True or false

Answers

Answer:

false is the answer okkkkkkkkkkkkkkkk

Type the correct answer in the box. Spell all words correctly.
Graphic designers can compress files in different formats. One of the formats ensures that the quality and details of the image are not lost when the graphic designer saves the file. Which file format is this?
The _______file format ensures that images don’t lose their quality and details when graphic designers save them.

Answers

Answer: TIFF

Explanation:

Tag Image File Format (TIFF) is the go to file format when one needs to store their image without worrying about it losing its quality and details. This is why TIFF images do not become smaller when compressed because they aim to save the quality of the work.

One has access to options such as tags and transparency on TIFF and it can be used on Photoshop as well as for things like desktop publishing and faxing.

Answer:

The lossless file format ensures that images don’t lose their quality and details when photographers save them.

Explanation:

Declare and implement a function called gameOver.gameOver receives a single 3x3 char[] [] array as a parameter, representing a tic-tac-toe board, with each cell containing either a X, a 0, or a (blank space). gameOver should return x if x has won the game, o ifo has won the game, and a blank space (' ') otherwise. Do not check the diagonals!

Answers

Answer:

The function in C++ is as follows:

char gameOver(char arr[][3]){

   char winner = ' ';

   if((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||(arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') || (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X')||(arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||(arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') || (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X')){

       winner = 'X';

   }

   else if((arr[0][0] == 'O' && arr[0][1] == 'O' && arr[0][2] == 'O') ||(arr[1][0] == 'O' && arr[1][1] == 'O' && arr[1][2] == 'O') || (arr[2][0] == 'O' && arr[2][1] == 'O' && arr[2][2] == 'O')||(arr[0][0] == 'O' && arr[1][0] == 'O' && arr[2][0] == 'O') ||(arr[0][1] == 'O' && arr[1][1] == 'O' && arr[2][1] == 'O') || (arr[0][2] == 'O' && arr[1][2] == 'O' && arr[2][2] == 'O')){

       winner = 'O';

   }

   return winner;

}

Explanation:

The function checks for the winning character by checking for matching rows and matching columns.

When either X or O fall in the any of the following 6 conditions , then that character (X or O) wins.

The position are:

Rows: (1) 00, 01 and 02 (2) 10, 11 and 12 (3) 20, 21 and 22

Columns: (4) 00, 10 and 20 (5) 01, 11 and 21 (6) 02, 12 and 22

So, the explanation is:

This defines the function gameOver

char gameOver(char arr[][3]){

This initializes winner to blank space

   char winner = ' ';

If any of the condition stated above matches X, then X wins

   if((arr[0][0] == 'X' && arr[0][1] == 'X' && arr[0][2] == 'X') ||(arr[1][0] == 'X' && arr[1][1] == 'X' && arr[1][2] == 'X') || (arr[2][0] == 'X' && arr[2][1] == 'X' && arr[2][2] == 'X')||(arr[0][0] == 'X' && arr[1][0] == 'X' && arr[2][0] == 'X') ||(arr[0][1] == 'X' && arr[1][1] == 'X' && arr[2][1] == 'X') || (arr[0][2] == 'X' && arr[1][2] == 'X' && arr[2][2] == 'X')){

       winner = 'X';

   }

If otherwise that it matches O, then O wins

   else if((arr[0][0] == 'O' && arr[0][1] == 'O' && arr[0][2] == 'O') ||(arr[1][0] == 'O' && arr[1][1] == 'O' && arr[1][2] == 'O') || (arr[2][0] == 'O' && arr[2][1] == 'O' && arr[2][2] == 'O')||(arr[0][0] == 'O' && arr[1][0] == 'O' && arr[2][0] == 'O') ||(arr[0][1] == 'O' && arr[1][1] == 'O' && arr[2][1] == 'O') || (arr[0][2] == 'O' && arr[1][2] == 'O' && arr[2][2] == 'O')){

       winner = 'O';

   }

This returns the winner (either O, X or blank)

   return winner;

See attachment for complete program which includes the main

Write a function longer_string() with two string input parameters that returns the string that has more characters in it. If the strings are the same size, return the string that occurs later according to the dictionary order. Use the function in a program that takes two string inputs, and outputs the string that is longer.

Answers

Answer:

Here you go :)

Explanation:

Change this to your liking:

def longer_string(s1, s2):

   if len(s1) > len(s2):

       return s1

   elif len(s1) < len(s2):

       return s2

   else:

       return s2

x = input("Enter string 1: ")

y = input("Enter string 2: ")

print(longer_string(x, y))

Write a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. The output should include the input character and use the plural form, n's, if the number of times the characters appears is not exactly 1.You may assume that the string does not contain spaces and will always contain less than 50 characters.

Ex: If the input is:

n Monday
the output is:

1 n
Ex: If the input is:

z TodayisMonday
the output is:

0 z's
Ex: If the input is:

n It'ssunnytoday
the output is:

2 n's
Case matters.

Ex: If the input is:

n Nobody
the output is:

0 n's
n is different than N.
C programming.

Answers

Answer:

The program and input is different than n, and it’s sunny today.

Where or what website can I download anime's? For free ​

Answers

https://todo-anime.com/

Other Questions
A bird lands on a bird feeder which is connected to a spring. The mass of the bird is exactly the same as the mass of the bird feeder. How does the added mass affect the period of oscillation of the bird feeder? need some help!!!!!!! please Assume that the British government eliminates all controls on imports by British companies. Other things being equal, the U.S. demand for pounds would ____, the supply of pounds for sale would ____, and the equilibrium value of the pound would ____. a. remain unchanged; increase; decrease b. remain unchanged; increase; increase c. decrease; increase; decrease d. increase; increase; increase CHAPTERCHAPTER ASSESSMENTUnderstanding Main Ideas (Part A)In the space at the left, write true if the statement is true; if the statement is false,change the italicized term to make it true.1. The overall charge of a formula unit for a compound is never zero.2. In a crystal lattice, each positive ion is surrounded by negative ions.3. Delocalized valence electrons are typical of ionic compounds.4. A sulfate ion contains fewer oxygen atoms than a sulfite ion does.true5. Metals tend to be malleable and ductile and to have relatively highmelting points.6. The more negative the lattice energy is, the stronger is the force ofattraction between the ions of an ionic compound.7. In naming ionic compounds, the cation is named first.8. When a metal reacts with a nonmetal, the metal tends to gain electrons.9. In naming a monatomic anion, the suffix -ide is used.10. The prefix per- is used in naming the anion with the most oxygen atoms. Both Kendra and maria tutor students after school. The table below shows the amount of money Kendra earned tutoring after school based on the number of hours tutored. maria calculates her earnings based on the number of hours she does using the equation P=9.1h. They each tutored 22 hours last week. who made the most money The expression (2x + 6) + x represents the perimeter of an isosceles triangle. If x represents the length of one side of the triangle, explain how you can use Distributive Property to find the length of each of the two equivalent sides? Write the unit rate for $17 for 5 cards A ramp has an angle of inclination of 20 degrees. it has a vertical height of 1.8 m. what is the length, l metres, of the ramp? Why did the people try and kill Saint Benedict? can someone solve this:a = 21+(-4) Resuelve el crucigrama y completa las frases adverbiales. 37 grams of H3PO4 ???? Who won the 2020 super bowl? ANSWER ASAP!!!!! 20 POINTS + BRAINLIEST!!!!!!!! A store sells 6 oranges for $3 what is the cost for 10 oranges ???? PLSSSS :( 1. Which of the following does NOT typically produce offspring with genetic variation?a. Humansb. Dogsc. Treesd. Bacteria Question 1 What is the area of a rectangle that is 1/2 feet long and 2/3 feet wide?Hint: Put the fraction in form A:3/5B;1/3C:2/6 How does Ulrich von Gradwitz's point of view about his neighbor, Georg Znaeym, change from the beginning of the story to the end? Ok, so this is what kangaroos used to look like...Enjoy trying to sleeping tonight ;) Dinesh notices that his prescription dosage states the term eod. How often should Dinesh take his medicine?A. once a dayB. twice a dayC. three times a dayD. four times a dayE. every alternate day