Anda di halaman 1dari 2

TUGAS 10 PEMROGRAMAN BERBASIS OBJEK

(APLIKASI BERBASIS TEKS)


Oleh : Chandra Sya’bana (1101202541)

1. Buatlah program untuk menentukan kelompok suatu karakter yang dimasukkan melalui
keyboard. Kelompok karakter tersebut adalah huruf kecil, huruf besar, angka, dan
karakter khusus (tanda baca, operator dan sebagainya).

import java.util.Scanner;
class CharChecker
{
static void checkChar(char key)
{
boolean CekInt = Character.isDigit(key);
if (CekInt){
System.out.println(key + " is Number");
} else{
if (key >= 'A' && key <= 'Z')
System.out.println(key + " is UpperCase character");

else if (key >= 'a' && key <= 'z')


System.out.println(key + " is LowerCase character" );

else
System.out.println(key + " is Special character" );
}

}
public static void main(String []args)
{
Scanner InputKey = new Scanner(System.in);
System.out.print("Enter Char: ");

char CharKey = InputKey.next().charAt(0);


checkChar(CharKey);
}
}
2. Bilangan bulat faktorial n, ditulis dengan n! adalah dihasilkan dari mengalikan dari 1
sampai dengan n. Contohnya 5! = 1 x 2 x 3 x 4 x 5 =120. Buatlah program untuk
menampilkan tabel hasil faktorial dari suatu bilangan yang diinputkan (tampilan
bilangan rata kanan)!

Contoh tampilan

import java.util.Scanner;
class Factorial {
static void Factorial(int num) {
System.out.println("n\t\tn!");
System.out.println("---------------");

int fact = 1;
for (int i = 1; i <= num; i++) {
fact = fact * i;
System.out.println(i + "\t\t" + fact);
}
System.out.println("---------------");

public static void main(String[] args) {


Scanner Input = new Scanner(System.in);
System.out.print("Enter factorial number: ");

int FactorialValue = Input.nextInt();


Factorial(FactorialValue);
}
}

Anda mungkin juga menyukai