Map

Translate

English French German Spain Italian Dutch

Russian Brazil Japanese Korean Arabic Chinese Simplified
Translate by Google ( UBLO 7 )

visitor

Flag Counter

About Me

PROGRAM MENGHITUNG BILANGAN GENAP DAN PENJUMLAHANNYA MENGUNAKAN WHILE (JAVA)

Dengan menggunakan while statement coba Anda tampilkan bilangan genap dari 1 s.d. 20, kemudian hitunglah jumlah semua bilangan tersebut!

CODE :

package package5;

import java.util.Scanner;

public class WhileSum {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
@SuppressWarnings({ "resource", "unused" })
Scanner sclim = new Scanner(System.in);
System.out.println("Bilangan Genap antara 1-20 = ");
System.out.println("-----");
int sum = 0, number = 1;
while(number<=20){
    if((number!=1)&&(number%2==0))
        sum= sum + number;
    if((number!=1)&&(number%2==0))
        System.out.println(number);
    number++;
        }

System.out.println("-----");

System.out.printf("total bilangan genap 1 s.d 20 = %d", sum);

    }

}





HASIL :


0 komentar:

Posting Komentar