Question

(This for java) Have to find the value of z int y= 3; int z =4;...

(This for java)

Have to find the value of z

int y= 3;

int z =4;

switch (y+4) {

   case 6: z=2; break;

   case 7: z=3; break;

default: z+=5;

}

Homework Answers

Answer #1

Answer: The value of z is equal to 3.Because in switch statement given y+4 which is equal to 7 as y=3.Then case 7 in the switch statement executes.In this the variable z is assigned as 3.Therefore the value of z is 3.The below program shows this.

Code:

public class Test
{
public static void main(String args[])
{
int y = 3;
int z = 4;
switch(y+4)
{
case 6: z = 2;
    break;
case 7: z = 3;
    break;
default: z += 5;
    }
System.out.println("The value of z is: "+z);
}
}

Screenshot:

Output:

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
How can I alter this Java method so that I convert and then return every sentence...
How can I alter this Java method so that I convert and then return every sentence in the array of strings instead of just the first sentence? public static char[] charConvert ( String [] sentences ) { int totLength = sentences[0].length() + sentences[1].length() + sentences[2].length() + sentences[3].length() + sentences[4].length(); char [] letter = new char[totLength]; int x = 0; int y = 0;    while ( y < sentences[x].length() ) { switch ( sentences[x].charAt(y) ) { case 'a': case 'A':...
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;...
1. What is the output of the following code fragment? (All variables are of type int.)...
1. What is the output of the following code fragment? (All variables are of type int.) limit = 8; cout << 'H'; for (loopCount = 10; loopCount <= limit; loopCount++) cout << 'E'; cout << "LP"); 2. What is the output of the following code fragment if the input value is 4? (Be careful here.) int num; int alpha = 10; cin >> num; switch (num) { case 3 : alpha++; case 4 : alpha = alpha + 2; case...
so I want to ask the user for a matrix size coding language is java. int...
so I want to ask the user for a matrix size coding language is java. int x = rows int y = columns for int x = 3 and int y = 3 I want to print 1 2 3 4 5 6 7 8 9 and for each dimension I would print number the start from 1 to the end so for int x = 4 and int y = 2 I would print 1 2 3 4 and...
1. Suppose that x, y, z, and w are int variables. What is stored in x,...
1. Suppose that x, y, z, and w are int variables. What is stored in x, y, z, and w after the following statements execute? (3, 6) x = 9; y = x - 4; z = (y + 7) % 6; w = (x * z) / y - 3; z = w + (x - y + 2) % x)
Java Write a program that prints the letters corresponding to the numbers on the telephone. So...
Java Write a program that prints the letters corresponding to the numbers on the telephone. So if you were to enter 6 it should print MNO. Now since you do not know how to do a System.in just do you for the number 7. So your code should be like int numberEntered = 7; String value; swtich (numberEntered){ case 1: value = "Nothing definded for 1"; break; case 2 : value = "A,B,C"; break ..... ..... default: value = "Not...
Write a java program that prints the letters corresponding to the numbers on the telephone. So...
Write a java program that prints the letters corresponding to the numbers on the telephone. So if you were to enter 6 it should print MNO. Now since you do not know how to do a System.in just do you for the number 7. So your code should be like int numberEntered = 7; String value; swtich (numberEntered){ case 1: value = "Nothing definded for 1"; break; case 2 : value = "A,B,C"; break ..... ..... default: value = "Not...
In Java is there a way I can put a value in a linkList = array[...
In Java is there a way I can put a value in a linkList = array[ ] string (I don't know how to word it here what I have so far with my code) * Example object 51 I want to equal Array [0]; // Project code below public String getCardRank() { String values[] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"}; return "RRR"; } // this part is in another .java file private...
The ability to read through Java™ code and predict the results, given specific inputs, is an...
The ability to read through Java™ code and predict the results, given specific inputs, is an extremely useful skill. For this assignment, you will be analyzing the Java™ code in the linked zip file, and predicting the results given specific input. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What would the output of the program be if you...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x)...
Java programming. 1) What, if anything, is wrong with the following Java code? void test(String x) { switch (x) { case 1: break; case 2: break; case 0: break; default: break; case 4: break; } } Select one: a)Each case section must end with a break statement. b)The case label 0 must precede case label 1. c)There is nothing wrong with the Java code. d)The default label must be the last label in the switch statement. e)The variable x does...