Jumat, 17 Maret 2017

Program hitungan deret 10 genap dan ganjil serta program menampilkan deret fibonanci dan bilangan Prima

1. Buatlah program untuk menghitung 10 deret bilangan genap ;
      input / program tsb ;......

 "     import java.io.*;

class genap

{
public static void main(String[]args){
int i = 0;
int x = 0;
System.out.print("Deret: ");
while(x<20){
if (i%3==0)
i++;
x = 2 * i;
System.out.print(" "+ x +", ");
i++;}
System.out.println(" ");
}
}     "

inilah hasil output program ini :




2.  Buatlah program untuk menghitung 10 deret bilangan ganjil ;

input program tersebut ;

"  public class array2
{
    public static void main(String[] args) {
        int [] bil = {1, 3, 5, 7, 9, 11, 13, 15, 17, 19 };
        System.out.println("");
       System.out.print("Bilangan Ganjil :  ");
       for (int i = 0; i < bil.length; i++){
           if (bil [i] % 2!= 0){
               System.out.print(bil[i] + " ");
           }
       }
       System.out.println("");
   }
}
"

inilah hasil program tersebut ;




3.  program untuk menampilkan deret fibonanci ;

input program fibinaci ;

"   class deretfibonacci
{
public static void main (String [] args)
{
int  t=0, p=1, hasil=0;
int x = Integer.parseInt(s);
for(int i=1; i<=x; i++){
t=p;
p=hasil;
System.out.print(hasil+" ");
hasil=t+p;
}
}
}

"

hasil output program fibonacci ;



4. program untuk menampilkan bilangan prima ;

input program bilangan prima ;

"    import java.util.Scanner;
public class prima
{
                public static void main (String [] args)
                {
                                Scanner input = new Scanner(System.in);
                               
                                int x=2;
                                int hitung=1;
                                boolean prima;
                               
                                System.out.print("input angka = ");
                                int angka = input.nextInt();
                               
                                while (hitung<=angka)
                                {
                                                prima = false;
                                                if (x==2 || x==3 || x== 5)
                                                {
                                                                prima = true;
                                                }
                                                else if (x%2 !=0)
                                                {
                                                                if (x%3 !=0)
                                                                {
                                                                                if(x%5 !=0)
                                                                                {
                                                                                                prima = true;
                                                                                }
                                                                }
                                                }
                                                if (prima==true)
                                                {
                                                                System.out.print(x+" ");
                                                                hitung++;
                                                }
                                                x++;
                                }
                }
}


"

output program bilangan prima ;


1 komentar:

Best Casino Near Me | MapyRO
This casino is one 공주 출장마사지 of the largest of all the gambling sites around. Located in the 진주 출장안마 heart of Central 남양주 출장샵 Oregon, 강원도 출장샵 this 정읍 출장안마 casino is a short drive from the

Posting Komentar

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More