Question

Which value of variable a will make variable x equal to 3? Java int x =...

Which value of variable a will make variable x equal to 3? Java

int x = 0;
if (a > 0)

  if (a%4 == 1)

     x = x + 5;

    else

        if (a%3 == 0)

           x = x + 4;

        else

            x = x + 3;

else
    x = x + 2;

Homework Answers

Answer #1

answer is 7

when a = 7, x value become 3.

Explanation :

   int x = 0;
   int a = 7;
if (a > 0) True 7 > 0
if (a%4 == 1) False 7%4 = 3
x = x + 5;
else Execute this else block
if (a%3 == 0) False 7%3 = 1
x = x + 4;
else execute this else block
x = x + 3; x = 0 + 3 x = 3
else
x = x + 2;

variable a = 7, will make variable x equal to 3

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In Java 1. What will be the value of x after the following section of code...
In Java 1. What will be the value of x after the following section of code executes: int x = 3; if (x > 3)     x = x – 2; else     x = x + 2; A. 1 B.3    C.5              D.7 2. What will be the value of y after the following section of code executes: int y = 5, z = 3; if (y > 4){      z = 2;      y = y – 1;...
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class...
Java question Consider the following: 1 class SnoopDogg { 2 int count; 3 } 4 class Test { 5 public static void main ( String [] args ) { 6 SnoopDogg myCount = new SnoopDogg (); 7 myCount.count = 0; 8 int times = 0; 9 increment( myCount, times ); 10 System.out.println( myCount.count ); 11 System.out.println( times ); 12 } 13 public static void increment (SnoopDogg sd, int times ) { 14 sd.count = sd.count + 1; 15 times =...
java •Write a method product(int x, int y) which returns the product of multiplying x *...
java •Write a method product(int x, int y) which returns the product of multiplying x * y but doing it recursively. Recall that multiplication can be implemented as repeated addition. For example, 4 * 7 is the same as adding 7, 4 times: 7 + 7 + 7 + 7. •Write a main method that asks for two numbers, and returns their product by calling the product method. Compile and test your code in NetBeans and then on Hackerrank
In the attached FlexArray Java class, implement a method public int delete (int location) { }...
In the attached FlexArray Java class, implement a method public int delete (int location) { } that deletes the integer value stored at location in the array, returns it, and ensures that the array values are contiguous.  Make sure to handle the array empty situation.  What is the time-complexity of the method, if the array size is n. ***************************************************************************************************************************** public class FlexArray { int [] array; private int size; private int capacity; public FlexArray() { capacity=10; size=0; array=new int[10]; } public FlexArray(int...
Which is an invalid access for the vector? vector<int> numsList(5); int x = 3; Group of...
Which is an invalid access for the vector? vector<int> numsList(5); int x = 3; Group of answer choices numsList.at(x+2) numsList.at(x-3) numsList.at((2*x) - x) numsList.at(0) Program: C++ Single choice
Machine Language - 1. Which of the following assembly code represents the high-level Java code below?...
Machine Language - 1. Which of the following assembly code represents the high-level Java code below? int x; int i = 5; if (i < 0) x = -1; else x = 1; @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JGE @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END 0;JMP @5 D=M @i M=D @BRANCH M;JLT @x M=1 @END 0;JMP (BRANCH) @x M=-1 (END) @END...
Draw a program flow graph for the function below int binsearch(int x,int v[],int n) { int...
Draw a program flow graph for the function below int binsearch(int x,int v[],int n) { int low,high,mid; low=0; high=n-1; while(low<high) { mid = ( low + high ) / 2; if( x < v[mid]) high = mid - 1; else if ( x > v[mid]) low = mid + 1; else return mid; } return -1; }
7. Which test case below can kill the mutant? Mutant: int x = read(); // x...
7. Which test case below can kill the mutant? Mutant: int x = read(); // x is the input x = 2*x; if (x > 5){     printf(“%d”, x); }else{             print(“%d”, x/2); // Original: print(“%d”, x-2); } A. x = 4 B. x = 3 C. x = 2 D. x = 1
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT