Just another WordPress.com site

Archive for November 9, 2010

Tugas Permodelan . Mencari Bilangan ganjil, genap, postif dan Negatif

import java.util.Scanner;

public class mencaribilangan{

public static void main (String [] args){

int bil, genap=0, ganjil=0, positif=0, negatif=0, total=-1;

Scanner input=new Scanner(System.in);

System.out.print(“Progam Mencari bilangan  \n”);

System.out.print(“GeNap, Ganjil\n”);

System.out.print(“Positif dan Negatif\n”);

System.out.print(“\n\n\n”);

do {

System.out.print(“Nilai : “);

bil = input.nextInt();

total++;

if(bil != 7)

if(bil%2==0)

genap++;

else

ganjil++;

if(bil > 0)

positif++;

if(bil < 0)

negatif++;

}

while ( bil != 7);

System.out.print(“Jumlah Bilangan Ganjil = ” + ganjil +”\n”);

System.out.print(“Jumlah Bilangan Genap = ” + genap +”\n”);

System.out.print(“Jumlah Bilangan Positif = ” + positif +”\n”);

System.out.print(“Jumlah Bilangan Negatif = ” + negatif +”\n”);

System.out.print(“Total Bilangan = ” + total +”\n”);

}

}