PROGRAM DERET BILANGAN DAN PENJUMLAHANNYA (JAVA)
17.16 |
Diposting oleh
Unknown |
Edit Entri
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);
}
}
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 :
Langganan:
Posting Komentar (Atom)
Jam
Pesan
Salju
Anime
Blog Archive
-
▼
2013
(23)
-
▼
Desember
(17)
- PROGRAM DERET BILANGAN DAN PENJUMLAHANNYA (JAVA)
- PROGRAM MENGHITUNG FAKTORIAL DAN DERET BILANGAN PE...
- PROGRAM DERET BILANGAN (C++)
- PROGRAM SEWA MOBIL PERHARI (JAVA)
- PROGRAM MENAMPILKAN BILANGAN GANJIL (C++)
- PROGRAM MENYATAKAN BILANGAN GENAP DAN GANJIL (C++)
- PROGRAM MENGHITUNG RUMUS TABUNG (JAVA)
- PROGRAM MENAMPILKAN BILANGAN GENAP DAN DIJUMLAH ME...
- PROGRAM MENGHITUNG KELIPATAN 4 DI PANGKAT 2 DAN DI...
- PROGRAM MENGHITUNG BILANGAN GENAP DAN PENJUMLAHANN...
- BELAJAR PEMROGRAMAN HTML
- Program untuk menghitung gaji pegawai
- PEMAKAIAN KODE ASCII Pada Program C++
- HyperText Markup Language (HTML)
- Program Input nama hari
- Program C++ (Market Sederhana 2)
- Program C++ (Market Sederhana)
-
▼
Desember
(17)
0 komentar:
Posting Komentar