This is default featured slide 1 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 2 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Ad

Sabtu, 14 Juli 2012

Menampilkan Bilangan Terbesar, Terkecil dengan Java Programming


import java.util.Scanner;

public class nomor2 {
    public static void main (String []args) {
    Integer totalgenap,totalganjil,totalpositiv,totalnegatif,nilai;
    int max=Integer.MIN_VALUE;
    int min=Integer.MAX_VALUE;
    Scanner input = new Scanner(System.in);

    totalgenap=0;
    totalganjil=0;
    totalpositiv=0;
    totalnegatif=0;

    do {
        System.out.print("Nilai : ");
        nilai=input.nextInt();
        if (nilai%2==0)
            totalgenap+=nilai;
        else
            totalganjil+=nilai;

        if (nilai>0)
            totalpositiv+=nilai;
        else
            totalnegatif+=nilai;

        if(nilai>max)
            max=nilai;
        if(nilai<min)
            min=nilai;

    } while (nilai!=0);

        System.out.printf("\nBilangan Terbesar           : %d\n",max);
        System.out.printf("Bilangan Terkecil           : %d\n",min);
        System.out.printf("Total Nilai Bilangan Ganjil : %d\n", totalganjil);
        System.out.printf("Total Nilai Bilangan Genap  : %d\n", totalgenap);
        System.out.printf("Total Nilai Bilangan Positif: %d\n", totalpositiv);
        System.out.printf("Total Nilai Bilangan Negatif: %d\n", totalnegatif);
        System.out.printf("\n");
    }
}


Contoh outputnya :
 

Source Code Menampilkan Bilangan Genap, Ganjil, Positif, Negatif dengan Java

import java.util.Scanner;

public class nomor1 {
    public static void main (String []args) {
    Integer genap,ganjil,positiv,negatif,nilai,total;
    Scanner input = new Scanner(System.in);

    genap=0;
    ganjil=0;
    positiv=0;
    negatif=0;
    total=0;

    do {
        System.out.print("Nilai : ");
        nilai=input.nextInt();
        if (nilai%2==0)
            genap++;
        else
            ganjil++;
        if (nilai>0)
            positiv++;
        else
            negatif++;

        total++;
    } while (nilai!=0);
        System.out.printf("\nBanyaknya Bilangan Ganjil  : %d\n", ganjil);
        System.out.printf("Banyaknya Bilangan Genap   : %d\n", genap-1);
        System.out.printf("Banyaknya Bilangan Positiv : %d\n", positiv);
        System.out.printf("Banyaknya Bilangan Negatif : %d\n", negatif-1);
        System.out.printf("Total Banyaknya Bilangan   : %d\n", total-1);
        System.out.printf("\n");
    }
}


Contoh Outputnya :