cara menentukan jenis karakter dalam kalimat dengan java

cek kodingnya langsung gan :D



   //tugas Daspro
// by bobby syahronanda
//11251103249
//input Scanner
import java.util.Scanner;
public class ujiKalimat
{
public static void main(String [] args)
{
Scanner tes = new Scanner(System.in);
 System.out.print("Masukkan kata atau kalimat : ");
 String kata = tes.nextLine();
 //perulangan menggunakan for
 //kata.length untuk menghitung panjang karakter yang diinputkan
 for (int i = 0; i <kata.length(); i++)
 {
 //jadikan ke char untuk memisahkan kata atau kalimat
  char c = kata.charAt(i);
 //konversi ke String
  String A = Character.toString(c);
  //vokal
  if (A.equalsIgnoreCase("a") | A.equalsIgnoreCase("i") | A.equalsIgnoreCase("u") | A.equalsIgnoreCase("e") | A.equalsIgnoreCase("o"))
  {
   System.out.println(A +" adalah huruf vokal ");
  }
  //angka
  if (c == '0'| c == '1'| c == '0'| c == '2'| c == '3'| c == '4'| c == '5'| c == '6'| c == '7'| c == '8'| c == '9')
  
  {
   System.out.println(A +" adalah Angka ");
  }
  //konsonan
  if (A.equalsIgnoreCase("b") | A.equalsIgnoreCase("c") | A.equalsIgnoreCase("d") | A.equalsIgnoreCase("f") | A.equalsIgnoreCase("g")
  |A.equalsIgnoreCase("h") | A.equalsIgnoreCase("j") | A.equalsIgnoreCase("k") | A.equalsIgnoreCase("l") | A.equalsIgnoreCase("m")
  | A.equalsIgnoreCase("n") | A.equalsIgnoreCase("p") | A.equalsIgnoreCase("q") | A.equalsIgnoreCase("r") | A.equalsIgnoreCase("s")
  |A.equalsIgnoreCase("t") | A.equalsIgnoreCase("v") | A.equalsIgnoreCase("w") | A.equalsIgnoreCase("x") | A.equalsIgnoreCase("y")
  | A.equalsIgnoreCase("z"))
  {
   System.out.println(A +" adalah huruf konsonan ");
  }
  else
  //spasi
  if ( c == ' ')
  {
   System.out.println(A +" adalah spasi ");
  }
  
  else
  //simbol (yang ada di keyboard :D
  if (A.equalsIgnoreCase("!") | A.equalsIgnoreCase("@") | A.equalsIgnoreCase("#") | A.equalsIgnoreCase("$") | A.equalsIgnoreCase("%")
  |A.equalsIgnoreCase("^") | A.equalsIgnoreCase("&") | A.equalsIgnoreCase("*") | A.equalsIgnoreCase("(") | A.equalsIgnoreCase(")")
  | A.equalsIgnoreCase("-") | A.equalsIgnoreCase("=") | A.equalsIgnoreCase("_") | A.equalsIgnoreCase("+") | A.equalsIgnoreCase("[")
  |A.equalsIgnoreCase("]") | A.equalsIgnoreCase("{") | A.equalsIgnoreCase("}") | A.equalsIgnoreCase("|") | A.equalsIgnoreCase("\\")
  | A.equalsIgnoreCase(";")| A.equalsIgnoreCase(":")| A.equalsIgnoreCase("'")| A.equalsIgnoreCase(".")| A.equalsIgnoreCase(",")
  | A.equalsIgnoreCase(";")| A.equalsIgnoreCase("?")| A.equalsIgnoreCase("\"")| A.equalsIgnoreCase(";")| A.equalsIgnoreCase(";")
  | A.equalsIgnoreCase("<")| A.equalsIgnoreCase(">")| A.equalsIgnoreCase("`")| A.equalsIgnoreCase("~"))
  {
   System.out.println(A +" adalah simbol ");
  }
 }
}
}
//thanks :D



Post a Comment

0 Comments