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 DERET BILANGAN DAN PENJUMLAHANNYA (JAVA)

Based on looping exercise where you are asked to display number between range of values (start to stop). You should implement the exception to validate the input of start and stop are only integer number. For this purpose use the exception to check integer number. You also need to use input dialog to read start and stop integer value.

Input:
Variables of start and stop (must be integer value) by using input dialog!
Validate by using exception for integer number only.

Process:
Display the number between start to stop range!

Output:
Count total number from start to stop! Using specifier!

CODE :
package package08;

import java.util.Scanner;

public class DeretBilangan {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        System.out.println("PROGRAM MENGHITUNG DERET BILANGAN");
        System.out.print("\nMasukan Bilangan Awal : ");
        int awal = sc.nextInt();
        System.out.print("Masukan Bilangan Akhir: ");
        int akhir = sc.nextInt();
        int total = 0;
        int jmlh = 1-awal+akhir;
        System.out.print("Total Bilangan" +" "+ "=" + " ");
        while (awal <= akhir) {
            System.out.print(awal + " ");
            System.out.print("+");
            System.out.print(" ");
            total += awal;
            awal++;      
        }
        System.out.print("=" + " " + total);
        System.out.println("\nJumlah Bilangan = "  + jmlh);
    }
}

HASIL :

0 komentar:

Posting Komentar