Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我的脚本测试的Java帮助_Java - Fatal编程技术网

我的脚本测试的Java帮助

我的脚本测试的Java帮助,java,Java,我是个新手,正在努力学习Java。我搜索了所有的谷歌,但找不到解决我问题的方法。我希望我的代码打印出%java Shuffle1 a-b c-d,但它只运行并表示成功,但没有打印输出。这是我的密码: public class Shuffle1 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO cod

我是个新手,正在努力学习Java。我搜索了所有的谷歌,但找不到解决我问题的方法。我希望我的代码打印出%java Shuffle1 a-b c-d,但它只运行并表示成功,但没有打印输出。这是我的密码:

public class Shuffle1 {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        int x = 3;
        x = x - 1;
        while (x > 0){                            
            x = x - 1;
            System.out.print("-");
            if (x > 2){
                System.out.print("a");
                if (x == 2){
                    System.out.print ("b c");
                    if (x == 1){
                        System.out.print ("d");   
                    }
                }
            }
        }  
    }  
}

更改代码。我可以给你实际的代码,但如果你能把它编出来就更好了。:)这并没有给出你想要的答案。。但这确实教会了您Java如何以最简单的形式工作

public static void main(String[] args) {
        // TODO code application logic here

        int x = 3;
         while (x > 0){             // as long as x is greater than 0, run this loop               
        System.out.print("-");     // always print "-". Because there is no printing condition specified. Is this what you want ??

        if (x > 2){
        System.out.print("a");
         }

       else if (x == 2){
            System.out.print ("b c");
           }

       else  if (x == 1){
             System.out.print ("d");

         } 
        x = x - 1;                      //always better to decrement x at the end 
}

}

解释为什么会nice@TimCastelijns-努力。。正在尝试……:)@大卫瓦莱斯-我也是。。不是那个意思-事实上PLater if语句嵌套在前面的语句中。这不是;这不是你的意思。在每次打印后添加一个右大括号,而不仅仅是在所有语句的末尾运行代码,我会得到预期的输出,即--。仔细检查代码,您会发现您将x设置为3,将其更改为2,然后将其更改为1,这样您就不会输入if(x>2)语句。如果您告诉我们预期的输出,这会有所帮助。它的输出是“-”(不成功),您预期的输出是什么?