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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With