Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main
- {
- public static void main(String coelhinhos[])
- {
- final int LIMIT = 150;
- Exercicios e = new Exercicios(LIMIT);
- System.out.println("Pares entre 1 e " + LIMIT);
- e.ex1();
- System.out.println("\n\nPrimos ateh " + LIMIT);
- e.ex2();
- System.out.println("\n\nFibonacci ateh " + LIMIT);
- e.ex3();
- }
- }
- class Exercicios
- {
- int limit = 100;
- public Exercicios(int limit)
- {
- this.limit = limit;
- }
- /* pares entre 1 e limit */
- void ex1()
- {
- for(int i = 2; i <= limit; i+=2) // hue
- {
- System.out.print(i + " ");
- }
- }
- /* primos ateh limit */
- void ex2()
- {
- for(int i = 2; i <= limit; i++)
- {
- boolean flag = false;
- for(int j = 2; j < i && !flag; j++)
- {
- if(i%j == 0)
- {
- flag = true;
- }
- }
- if(!flag)
- {
- System.out.print(i + " ");
- }
- }
- }
- /* fibonacci ateh limit */
- void ex3()
- {
- int a = 1;
- int b = 1;
- int c = a+b;
- System.out.print(a + " " + b + " ");
- while(c <= limit)
- {
- System.out.print(c + " ");
- a = b;
- b = c;
- c = a+b;
- }
- System.out.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment