Advertisement
Faldi767

Function ganjil

Nov 4th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package javaapplication25;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Hashtable;
  10. import java.util.Iterator;
  11.  
  12.  
  13. public class JavaApplication25 {
  14.  
  15. public static void main(String[] args) {
  16. // Arraylist
  17. ArrayList<String> al=new ArrayList<String>();
  18. al.add("Ravi");
  19. al.add("Vijay");
  20. al.add("Ravi");
  21. al.add("Ajay");
  22. Iterator itr=al.iterator();
  23. while(itr.hasNext()){
  24. System.out.println(itr.next());
  25. }
  26.  
  27. // Hashtable
  28. Hashtable<String,String> urutan = new Hashtable<String,String>();
  29. urutan.put("A1", "Nasi Goreng");
  30. urutan.put("A2","Mie Ayam");
  31. urutan.put("A3","Es Teler");
  32. urutan.put("A4", "Es Teh");
  33. urutan.put("A5","Es Campur");
  34. urutan.put("A6","Lalapan");
  35. urutan.put("A7", "Tahu Campur");
  36. urutan.put("A8","Nasi Pecel");
  37. urutan.put("A9","Soto Ayam");
  38. urutan.put("A10","Soto Daging");
  39. String str;
  40. for(int i=1;i<11;i++) {
  41. str = "A" + i;
  42. if(isganjil(str)) {
  43. System.out.println(str + " : " + urutan.get(str));;
  44. }
  45. }
  46. System.out.println("Value of key 'A4': "+urutan.get("A4"));
  47. System.out.println("Is Hashtable empty? "+urutan.isEmpty());
  48. urutan.remove("A3");
  49. urutan.remove("A5");
  50. System.out.println(urutan);
  51. System.out.println("Size of the Hashtable:"+urutan.size());
  52. }
  53. public static boolean isganjil(String a) {
  54. String b = a;
  55. b = b.replaceAll("[^0-9]", "");
  56. return Integer.parseInt(b) % 2 != 0;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement