How do I exit an if statement and continue the loop when the if statement is in the loop? I tried break but it didn't work. Continue just made the program to keep asking me to input a number.
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);
}
}
You just need to write the method in this way: public static void main(String args[])
If you want to use continue;
, you have to move n = n / 10;
line before if statement.
simple you have to write String[]args in main method. once you write it can be work properly.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.