Tugas Pertemuan 2 Algoritma

buatlah Program yang meminta inputan 1 huruf , dan tentukan huruf tsb huruf kecil atau huruf besar ,
apabila yang diinput lebih dari 1 huruf atau bukan huruf keluarkan pesan “Inputan Tidak Valid”

contoh :

Input : abc
Output : Inputan Tidak Valid

Input : 1
Output : Inputan Tidak Valid

Input : a
Output : Huruf Kecil

 

Coding =

import java.util.*;

public class HurufBesaratauKecil
{
public static void main(String[]args){

Scanner scan = new Scanner (System.in);

String huruf;
char huruf2;
int nomor;

System.out.print(“Masukkan huruf: “);

huruf = scan.next();
huruf2 = huruf.charAt(0);
nomor = huruf.length();

if(huruf2>=97 && huruf2<=122 && nomor==1){

System.out.println(“Huruf yang anda masukkan adalah huruf kecil”);
}
else if (huruf2>=65 && huruf2<=90 && nomor==1){

System.out.println(“Huruf yang anda masukkan adalah huruf besar”);
}
else{

System.out.println(“Input tidak valid”);
}

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.