how do i exit an if statement in java?

how do i exit an if statement in java?



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);






Use continue; instead of break;
– ernest_k
Aug 28 at 16:50


continue;


break;




2 Answers
2



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.


public static void main(String args)


continue;


n = n / 10;





Thx! I used continue and put the line before the if statement and it worked.
– Super Maniac
Aug 28 at 17:16





YW, Note that "i" variable is never used.
– hadiafifi
Aug 28 at 17:50




simple you have to write Stringargs in main method. once you write it can be work properly.





I tried that just now and it didn't work.
– Super Maniac
Aug 28 at 17:08





Thanks for wanting to contribute. The asker can best tell, but my suspicion is that this is not the problem asked about (you are correct, of course, that String... commandLineArgs or similar is missing).
– Ole V.V.
Aug 28 at 17:09



String... commandLineArgs






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)