Advertisement
Guest User

tugas error

a guest
Dec 19th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.48 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class tugas
  4. {
  5.     public static void main(String[]args)
  6.     {
  7.         Scanner scan = new Scanner(System.in);
  8.         int jmlhdata=0, choice = 0;
  9.         do
  10.         {
  11.             System.out.println("e-Phonebook");
  12.             System.out.println("===========");
  13.             System.out.println("1. Input Phonebook Data");
  14.             System.out.println("2. Tampilkan Isi Phonebook");
  15.             System.out.println("3. Exit");
  16.             System.out.print("Input Menu : ");
  17.             do
  18.             {
  19.                 try
  20.                 {
  21.                     choice = scan.nextInt();
  22.                     scan.nextLine();
  23.                 }
  24.                 catch(Exception e)
  25.                 {
  26.                     scan.nextLine();
  27.                     System.out.println("Input Yang Kamu Masukan Salah");
  28.                 }
  29.             }
  30.             while(choice <1 || choice >3);
  31.             switch(choice)
  32.             {
  33.                 case 1:
  34.                 if(jmlhdata !=0)
  35.                 {
  36.                     System.out.println("Tentukan Jumlah Data Yang Akan Di Input!");
  37.                     System.out.print("Jumlah Data : ");
  38.                     try
  39.                     {
  40.                         jmlhdata = scan.nextInt();
  41.                         scan.nextLine();
  42.                     }
  43.                     catch(Exception e)
  44.                     {
  45.                         scan.nextLine();
  46.                         System.out.println("Hanya Angka Yang Diperbolehkan!");
  47.                     }
  48.                 }
  49.                 String notelf[] = new String[jmlhdata];
  50.                 String user[] = new String[jmlhdata];
  51.                 String phonebook;
  52.                 for(int i = 0;i<notelf.length;i++)
  53.                 {
  54.                     System.out.print("Input Data [Nama # Nomor Telfon] : ");
  55.                     phonebook = scan.nextLine();
  56.                     if(!phonebook.contains("#"))
  57.                     {
  58.                         System.out.println("Format Phonebook Salah!");
  59.                         i--;
  60.                     }
  61.                     else
  62.                     {
  63.                         String[] book = phonebook.split("#");
  64.                         notelf[i] = book[0];
  65.                         user[i] = book[1];
  66.                     }
  67.                     System.out.println("Data Phonebook Telah Di Input");
  68.                     scan.nextLine();
  69.                 }
  70.                     break;
  71.  
  72.                 case 2:
  73.                 if(jmlhdata ==0)
  74.                 {
  75.                     System.out.println("Data Tidak Ada!");
  76.                 }
  77.                 else
  78.                 {
  79.                     for (int i = 0; i < notelf.length;i ++)
  80.                     {
  81.                         System.out.println("No : " +i);
  82.                         System.out.println("Nama : " +user[i]);
  83.                         System.out.println("No Telfon : " +notelf[i]);
  84.                         System.out.println();
  85.                     }
  86.                 }
  87.                 case 3:
  88.                 break;
  89.             }
  90.         }while(choice !=3);
  91.     }
  92. }
  93.  
  94.  
  95. C:\Users\Christianto Tri M P\SkyDrive\Documents\tugas.java:79: error: variable notelf might not have been initialized
  96.                     for (int i = 0; i < notelf.length;i ++)
  97.                                         ^
  98. C:\Users\Christianto Tri M P\SkyDrive\Documents\tugas.java:82: error: variable user might not have been initialized
  99.                         System.out.println("Nama : " +user[i]);
  100.                                                       ^
  101. 2 errors
  102.  
  103. Tool completed with exit code 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement