Tugas Praktikum package package1; import java.util.Scanner;
public class inputan extends inisial{ int jumlah,i,n,x; String kata; boolean boll=false; Scanner input = new Scanner(System.in); public void inputan()throws Exception { System.out.print("Masukkan Jumlah = "); jumlah=input.nextInt(); for(i=1; i<=jumlah; i++){ do { try{ System.out.print("Masukkan Kata"+i+" : "); kata=input.next(); int x; for(char n:kata.toCharArray()) { x=(int)n; if(!((x>=97 && x<=122) || (x>=65 &&x<=90) || (x>=48 && x<=57) )) { throw new Exception("Tulisan Mengandung simbol"); } }
boll=false; } catch (Exception ex) { System.out.println (ex.getMessage()); boll=true; }
Pemrograman Berorientasi Objek | Periode II | Tahun 2017/2018 | Lab. Rekayasa Perangkat Lunak
Tugas Praktikum }while(boll); setKata(kata,i); } System.out.println("Jumlah = "+jumlah); for (int i=1;i<=jumlah;i++) { n=i+1; for (int j = 2; j <=jumlah+1-i; j++) { System.out.print("Kata "+i+" sama dengan kata "+n+" : "); try { Thread.sleep(1000); } catch (Exception e) { } if(getKata(i).equals(getKata(n))) { System.out.print("True\n"); } else { System.out.print("False\n"); } n++; } } } }
Pemrograman Berorientasi Objek | Periode II | Tahun 2017/2018 | Lab. Rekayasa Perangkat Lunak
Tugas Praktikum package package1; public class inisial { private static String[] kata=new String[100]; protected void setKata(String kata,int i) { this.kata[i]=kata; } protected String getKata(int i) { return this.kata[i]; } }
package package1; import package1.*;
public class utama { public static void main(String[] args) throws Exception{ inputan ip = new inputan(); ip.inputan(); } }
Pemrograman Berorientasi Objek | Periode II | Tahun 2017/2018 | Lab. Rekayasa Perangkat Lunak