开发者

creating a java segment code [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.
segment of code: 

int x, y = 34, z = 19, w=11;

swtich (x) {
    case 1:     y += 4;
        z -= w;
        break;
    case 2:   w = (x++)*(--y);
        break;
    case 3: w = (--x)*(++y);
        break;
    case 4:   y -=7;
    case 5:   z *= 2;
        break;
    default:    w = (++x)*(++y);
}
System.out.println(“x = “ + x + “ y = “ + y + “  z = “ +  z + “  w = “ + w);

can someone help me fix up this code please?


For one thing, you forgot to put break; on CASE 4. Then if x is local variable, you forgot to initialize it. And how do you plan to input the x?

EDIT: It's working on my PC.

public class Main {

    public static void main (String[] args) {
        int x=0, y = 34, z = 19, w = 11;

        x = Integer.parseInt(JOptionPane.showInputDialog(x)); //this is how i input x  

        switch (x) {
            case 1:
                y += 4;
                z -= w;
                break;
            case 2:
                w = (x++) * (--y);
                break;
            case 3:
                w = (--x) * (++y);
                break;
            case 4:
                y -= 7;
                break;
            case 5:
                z *= 2;
                break;
            default:
                w = (++x) * (++y);
        }
        System.out.println("x = " + x + "y = " + y + "  z = " + z + "  w = " + w);
    }
}

illegal character: \8220 or \8221: You used Unicode 8220 (aka \u291c, 0x291c, “, left quote) or ... something of the form usually when you Copy Paste a code... Type again the System.out.println line especially the quote ("), maybe you copy paste it and it is in different form... For more details about errors check out this site


case 4 needs a break (unless you intended case 4 to "fall through" to case 5.


Your code has smart quote characters (), which aren't normal quotes and are not recognized by the Java language.

Change the characters to ".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜