Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sequencia de primos
- import java.util.Scanner;
- public class Primos {
- public static void main(String args[]) {
- Scanner leia = new Scanner(System.in);
- int cont = 0, t = 5, n = 1;
- System.out.print("Numero: ");
- n = leia.nextInt();
- System.out.print("Total: ");
- t = leia.nextInt();
- for(int i = n; i < t+n; i++) {
- cont = 0; // zera o contador
- for(int j = 1; j <= i; j++) {
- if(i % j == 0) {
- cont++;
- }
- }
- if(cont == 2) { /* Verifica se o numero eh primo. */
- System.out.print(i + " ");
- } else { /* Se nao for, aumenta o numero, consequentemente o total */
- n++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement