jamirooo Posted January 5, 2008 at 04:32 PM Report Share #158072 Posted January 5, 2008 at 04:32 PM boas! comecei a programar$ há pouco tempo e tenho aqui uma pequena dúvida... tenho um exercício que me pede para escrever um excerto de programa que imprima multiplos de 7 menor que 500, pois bem eu fiz isto: for (int x = 0; x<72; x++) System.out.println (x*7 + " "); e dá certo, imprime ate 497, mas antes de utilizar o for tentei o while e o do while e nao consegui nada....dava-me 2000 e tal....se alguem me ajudasse a por isto com outra iteração, agradecia! 😉 Link to comment Share on other sites More sharing options...
Hipnoted Posted January 5, 2008 at 04:35 PM Report Share #158074 Posted January 5, 2008 at 04:35 PM E que tal fazer de modo a que o while tenha uma condição de procura até 500? int num = 7; while(num<500){ System.out.println (num + " "); num += 7; } "Nunca discutas com um idiota. Eles arrastam-te até ao seu nível e depois ganham-te em experiência" Link to comment Share on other sites More sharing options...
jamirooo Posted January 5, 2008 at 04:41 PM Author Report Share #158076 Posted January 5, 2008 at 04:41 PM 😉 é isso mesmo...obrigadíssimo pela ajuda! 😉 Link to comment Share on other sites More sharing options...
Rui Carlos Posted January 5, 2008 at 05:09 PM Report Share #158084 Posted January 5, 2008 at 05:09 PM O equivalente ao teu código com um while seria: int x=0; while(x<72){ System.out.println (x*7 + " "); x++; } Rui Carlos Gonçalves Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now