Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class tugas
- {
- public static void main(String[]args)
- {
- Scanner scan = new Scanner(System.in);
- int jmlhdata=0, choice = 0;
- do
- {
- System.out.println("e-Phonebook");
- System.out.println("===========");
- System.out.println("1. Input Phonebook Data");
- System.out.println("2. Tampilkan Isi Phonebook");
- System.out.println("3. Exit");
- System.out.print("Input Menu : ");
- do
- {
- try
- {
- choice = scan.nextInt();
- scan.nextLine();
- }
- catch(Exception e)
- {
- scan.nextLine();
- System.out.println("Input Yang Kamu Masukan Salah");
- }
- }
- while(choice <1 || choice >3);
- switch(choice)
- {
- case 1:
- if(jmlhdata !=0)
- {
- System.out.println("Tentukan Jumlah Data Yang Akan Di Input!");
- System.out.print("Jumlah Data : ");
- try
- {
- jmlhdata = scan.nextInt();
- scan.nextLine();
- }
- catch(Exception e)
- {
- scan.nextLine();
- System.out.println("Hanya Angka Yang Diperbolehkan!");
- }
- }
- String notelf[] = new String[jmlhdata];
- String user[] = new String[jmlhdata];
- String phonebook;
- for(int i = 0;i<notelf.length;i++)
- {
- System.out.print("Input Data [Nama # Nomor Telfon] : ");
- phonebook = scan.nextLine();
- if(!phonebook.contains("#"))
- {
- System.out.println("Format Phonebook Salah!");
- i--;
- }
- else
- {
- String[] book = phonebook.split("#");
- notelf[i] = book[0];
- user[i] = book[1];
- }
- System.out.println("Data Phonebook Telah Di Input");
- scan.nextLine();
- }
- break;
- case 2:
- if(jmlhdata ==0)
- {
- System.out.println("Data Tidak Ada!");
- }
- else
- {
- for (int i = 0; i < notelf.length;i ++)
- {
- System.out.println("No : " +i);
- System.out.println("Nama : " +user[i]);
- System.out.println("No Telfon : " +notelf[i]);
- System.out.println();
- }
- }
- case 3:
- break;
- }
- }while(choice !=3);
- }
- }
- C:\Users\Christianto Tri M P\SkyDrive\Documents\tugas.java:79: error: variable notelf might not have been initialized
- for (int i = 0; i < notelf.length;i ++)
- ^
- C:\Users\Christianto Tri M P\SkyDrive\Documents\tugas.java:82: error: variable user might not have been initialized
- System.out.println("Nama : " +user[i]);
- ^
- 2 errors
- Tool completed with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement