如果if语句处于循环中,如何退出if语句并继续循环?我尝试中断,但没有成功。继续刚刚制作的程序,继续要求我输入数字。

import java.io.*;
public class pg48
{
    public static void main()throws IOException
    {
        InputStreamReader read = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(read);
        System.out.println("Type a num: ");
        int n = Integer.parseInt(in.readLine());
        int pro = 1,i,d;
        for (; n != 0; )
        {
            d = n%10;
            if (d == 0)
            {
                break;
            }
            pro = pro * d;
            n = n/10;
        }
        System.out.println("Product: "+pro);
    }
}

最佳答案

您只需要以这种方式编写方法:public static void main(String args[])
如果要使用continue;,则必须将n = n / 10;行移至if语句之前。

10-08 08:38
查看更多