Created
November 22, 2012 18:24
-
-
Save marioplumbarius/4132471 to your computer and use it in GitHub Desktop.
Programa em Java que armazena X números ímpares em um array e em seguida imprime na tela.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Declare um vetor de 10 posições | |
* preencha com os 10 primeiros números ímpares | |
* escreva na tela o resultado | |
*/ | |
package vetores; | |
public class Exercicio02 { | |
public static void main(String[] args){ | |
// declaração de vetor | |
int[] vetor = new int[10]; | |
// declaração de variáveis | |
int i = 0, slot = 0; | |
do{ | |
// validação números ímpares | |
if(i % 2 == 1){ | |
vetor[slot] = i; | |
slot++; | |
} | |
i++; | |
}while(slot < 10); | |
// zerando o valor de i | |
i = 0; | |
// imprimindo os números ímpares | |
for(; i < vetor.length; i++){ | |
System.out.println(vetor[i]); | |
} | |
} // fim main | |
} // fim class |
Muito obrigado, me ajudou muito!!
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int i = 1;
while(true) {
System.out.println(i);
i += 2;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Muito obrigado, me ajudou muito!!