Project

503 views
433 views

Published on

Listing program beserta tampilan hasil.
Project array java

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
503
On SlideShare
0
From Embeds
0
Number of Embeds
20
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Project

  1. 1. POLITEKNIK GORONTALO Teknik Informatika Taufiq Anugrah Ramadhan | 131311022 Mata Kuliah Struktur Data1. Listing Program Konversi kata Dari Huruf Besar menjadi Huruf Kecil dan huruf kecil menjadi Huruf Besar.!import java.util.Scanner;public class HurufBesartoKecil { /** * @param args */ // TODO Auto-generated method stub public static void main(String[] args) { System.out.println("============================================"); System.out.println("Menu"); System.out.println("********************************************"); System.out.println("1. Menampilkan Huruf Kecil Ke Huruf Besar"); System.out.println("2. Menampilkan Huruf Besar Ke Huruf Kecil1"); System.out.println("3. Keluar"); System.out.println("============================================"); Scanner input = new Scanner (System.in); System.out.println("Masukkan Pilihan:"); int pilihan; pilihan = input.nextInt(); if (pilihan == 1) { Scanner Kalimat = new Scanner(System.in); System.out.println("Ketikkan kalimat"); String ketik; ketik = Kalimat.nextLine(); System.out.println("Dalam huruf Kecil:n"+ketik.toUpperCase()); } else if (pilihan == 2) { Scanner kalimat = new Scanner (System.in); System.out.println("Ketikkan kalimat"); String ketik; ketik = kalimat.nextLine(); System.out.println("Dalam huruf besar:n"+ketik.toLowerCase()); } else if (pilihan == 3) { System.exit(0); } else {Taufiq Anugrah Ramadhan | taufiq@smart-ti.com 1
  2. 2. System.out.println("Tidak ada dalam pilihan"); } }}Display Konversi Huruf Kecil Ke Huruf BesarDisplay Konversi Huruf Besar Ke Huruf Kecil2. Listing Program konversi karakter bilangan ke integerimport java.util.Scanner;public class konvBiltoInt { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stubint angka=0;Taufiq Anugrah Ramadhan | taufiq@smart-ti.com 2
  3. 3. String bilangan="";pembukaan();angka = inputAngka(" Masukkan sembarang angka bulat: "," Maaf, angka yang andamasukkan salah EX: 123000 ");bilangan = prosesPemisahan(angka);bilangan = convertToBilangan(bilangan);System.out.println("n Bilangannya adalah : nn"+bilangan);System.out.println("nnn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");}private static void pembukaan() {System.out.println("nnnnn~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");System.out.println(" mengubah angka ke bilangan");System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~nnn");}private static int inputAngka(String string, String string0) {Scanner scan = new Scanner(System.in);boolean kembali=false;int angka=0;do{kembali=false;try{System.out.print(string);angka = scan.nextInt();}catch(Exception e){System.out.println();System.out.println(string0);System.out.println();kembali=true;}}while(kembali);return angka;}private static String prosesPemisahan(int angka) {String bilangan = String.valueOf(angka);bilangan = balikString(bilangan);bilangan = sisipTitik(bilangan);bilangan = balikString(bilangan);return bilangan;}private static String balikString(String bilangan) {String[] str=bilangan.split("");bilangan ="";for(int c=str.length-1; c>0;c-- ){bilangan = bilangan.concat(str[c]);}return bilangan;}private static String sisipTitik(String bilangan) {String[] str=bilangan.split("");bilangan="";for(int n=1; n<str.length; n++){bilangan = bilangan.concat(str[n]);if(n%3==0)bilangan = bilangan.concat("-");Taufiq Anugrah Ramadhan | taufiq@smart-ti.com 3
  4. 4. }return bilangan;}private static String convertToBilangan(String bilangan) {String[] pemisah={" ","ribu "," juta "," milyar "," trilyun "};String[] str=bilangan.split("-");//cekSpit(str);bilangan="";for(int n=0; n<str.length; n++){bilangan = bilangan.concat(ubahKeBilangan(str[n]));bilangan = bilangan.concat(pemisah[str.length-n-1]);}return bilangan;}private static String ubahKeBilangan(String string) {String[] bilAsli = {"", "satu ", "dua ", "tiga ", "empat ", "lima ", "enam ","tujuh ", "delapan ", "sembilan "};String[] bil = {"", " se", "dua ", "tiga ", "empat ", "lima ", "enam ", "tujuh ","delapan ", "sembilan "};String[] bilPendamping = {"", "puluh ", "ratus "};String[] str = string.split("");string = "";if (str.length == 2) {string = bilAsli[Integer.parseInt(str[1])];} else if (str.length == 3) {if (str[1].equals("1") && !str[2].equals("0")) {string = string.concat(bil[Integer.parseInt(str[2])]);string = string.concat("belas ");} else {string = string.concat(bil[Integer.parseInt(str[1])]);string = string.concat(bilPendamping[1]);string = string.concat(bilAsli[Integer.parseInt(str[2])]);}} else if (str.length == 4) {string = string.concat(bil[Integer.parseInt(str[1])]);string = string.concat("ratus ");if (str[2].equals("1") && !str[3].equals("0")) {string = string.concat(bil[Integer.parseInt(str[3])]);string = string.concat("belas ");} else {string = string.concat(bil[Integer.parseInt(str[2])]);string = string.concat(bilPendamping[1]);string = string.concat(bilAsli[Integer.parseInt(str[3])]);}}return string;} }Taufiq Anugrah Ramadhan | taufiq@smart-ti.com 4
  5. 5. Display konverter3. Mencari data terbesar dan data terkecil beserta letaknya.public class maxmin {public static void main(String[] arg) {int B[] = {10, 5, 14, 20, 1000, 27, 50, 7500};int jumlah = B[0];int indeks = 0;for (int n=1; n < B.length; n++){if ( jumlah < B[n]) {jumlah = B[n]; indeks = n;}} System.out.println("Bilangan terbesar adalah =" +jumlah);System.out.println(" indeks ke = " + indeks);}}Display max-minTaufiq Anugrah Ramadhan | taufiq@smart-ti.com 5

×