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
Angelina_Jolie [31]
4 years ago
7

Assume that x and y are integer variables that have been initialized to 20 and 10, respectively. What is the output of the follo

wing code segment? System.out.println( x + "\t" + y ); swap( x, y ); System.out.println( x + "\t" + y ); public static void swap( int a, int b ) { if( a > b ) { int temp = b; b = a; a = temp; } System.out.println( a + "\t" + b ); }
Computers and Technology
1 answer:
ad-work [718]4 years ago
8 0

Answer:

// here is the complete code in java to check the output.

import java.util.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

   try{

       int x=20,y=10;

       System.out.println( x + "\t" + y );

       swap( x, y );

       System.out.println( x + "\t" + y );

   }catch(Exception ex){

       return;}

}

public static void swap( int a, int b )

{

    if( a > b )

    {

        int temp = b;

        b = a;

        a = temp;

        }

        System.out.println( a + "\t" + b );    

}

}

Explanation:

Here is "x" is initialize with 20 and "y" is with 10. The first print statement  will print the value of "x" and "y"  separated by a tab. Then it will the swap() method with parameter x and y.In the swap method, if first parameter is greater then it will swap the two value and the print statement will execute. It will print 10 and 20 separated by a tab. then in the main method, print statement execute And print the value of x,y as 20 and 10. Here value of x, y will not change by the method swap() because in java parameters are passed by value not by reference.That is why  any change by swap() method will not reflect in the main method.

Output:

20      10                                                                                                                                                    

10      20                                                                                                                                                    

20      10

You might be interested in
Write a MATLAB program using afor loopto determine the number of values thatarepositive, the number of values that are negative,
murzikaleks [220]

Answer:

see description

Explanation:

clicking in new script, we type the following:

%inputs and variables

N = input('Enter N : ');

values = input('Enter values : ');

positive=0;

negatives=0;

zero=0;

%for loop

for c = 1:N

   if values(c) > 0

       positive = positive + 1;

   elseif values(c) < 0

       negatives = negatives + 1;

   else

       zero = zero + 1;

   end

end

positive

negatives

zero

so we basically loop the array and add one to counters each time we read an element from the input, for example if we enter:

Example input

Enter N : 5

Enter values : [1,-1,0,2,352]

positive = 3

negatives = 1

zero = 1

7 0
4 years ago
When would you use conditional formatting on a cell?
Charra [1.4K]
You use conditional formatting on a cell if the numbers are less then zero.
4 0
3 years ago
Any application that wants to be displayed on the web must use the HTTP protocol <br> True<br> False
never [62]

Answer:

true

Explanation:

7 0
3 years ago
With what for a human may a heatsink in the computer be compared? a crispy lettuce salad an ice cold drink of water a sizzling s
Marysya12 [62]

Answer: I'd say an ice cold drink

7 0
4 years ago
Write program to calculate the sum of the following series where in is input by user. (1/1 + 1/2 + 1/3 +..... 1/n)
Lorico [155]

Answer:

#here is code in Python.

#read the value n from user

n=int(input("enter the value of n:"))

#variable to store the total sum

sum_n=0

for i in range(1,n+1):

# find the sum of series

   sum_n=sum_n+1/i

#print the sum

print("sum of the series is: ",sum_n)

Explanation:

Read the value of n from user. Create and initialize a variable sum_n with 0. Run a for loop to calculate sum.Initially sum_n is 0, then for value of i=1  1/i will be added to the sum_n.Then in next iteration for i=1, 1/2 added to sum_n. Similarly loop will run util i equals to n.Then sum_n will store the sum of the

series.

Output:

enter the value of n:5

sum of the series is:  2.283333333333333

3 0
4 years ago
Other questions:
  • Positive thinkers tend to
    9·2 answers
  • Mr chen xi is a vedio maker in singapore . He had created 14GB vedio file for his customer is united states . Name and describe
    14·1 answer
  • Which tab in the Tasks view is used to modify the Current View?
    11·2 answers
  • This chapter uses the class rectangleType to illustate how to overload the operators +, *, ==, !=, &gt;&gt;, and &lt;&lt;. In th
    15·1 answer
  • A virus enters a computer or network _____.
    13·1 answer
  • Is phone data used when connected to wifi
    12·1 answer
  • When is the greatest risk of damage from electrostatic discharge?
    7·2 answers
  • Jjgdg gegg tget t446v
    15·2 answers
  • What is the term for delivering an application over the internet called?
    13·2 answers
  • Which program assesses and measures improper medicare fee-for-service payments (based on reviewing selected claims and associate
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!