Advertisement
Guest User

Untitled

a guest
May 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. //===========MAIN===========
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. package tablicamain;
  8.  
  9. /**
  10. *
  11. *
  12. */
  13. import java.util.Scanner;
  14. public class Tablicamain {
  15.  
  16. /**
  17. * @param args the command line arguments
  18. */
  19. static Scanner sc=new Scanner(System.in);
  20. public static void main(String[] args) {
  21.  
  22. System.out.println("podaj liczbe ");
  23. int n;
  24. n=sc.nextInt();
  25. String[] tab=new String[n];
  26. String napis = null;
  27. tablica t = new tablica(n,napis);
  28. for(int i=0;i<n;i++)
  29. {
  30. System.out.println("podaj napis ");
  31. napis = sc.nextLine();
  32. t.wypelnij(i, napis, tab);
  33. }
  34. t.wypisz(n, tab);
  35. System.out.println(" ");
  36. System.out.println("--------");
  37. int a;
  38. a=sc.nextInt();
  39. t.wypiszp(a, n, tab);
  40.  
  41. }
  42.  
  43. }
  44.  
  45. //=============TABLICA==========
  46.  
  47. /*
  48. * To change this license header, choose License Headers in Project Properties.
  49. * To change this template file, choose Tools | Templates
  50. * and open the template in the editor.
  51. */
  52. package tablicamain;
  53.  
  54. /**
  55. *
  56. *
  57. */
  58. public class tablica {
  59. int n;
  60. String napis;
  61. public tablica(int n,String napis)
  62. {
  63. this.n=n;
  64. this.napis=napis;
  65. }
  66. public void wypelnij(int ile,String co,String[] gdzie)
  67. {
  68.  
  69. gdzie[ile]=co;
  70.  
  71. }
  72.  
  73. public void wypisz(int ile,String[] co)
  74. {
  75. for(int i=0;i<ile;i++)
  76. {
  77. System.out.print(co[i]+" ");
  78. }
  79. }
  80.  
  81. public void wypiszp(int n,int ile,String[] co)
  82. {
  83. for(int i=0;i<ile;i++)
  84. {
  85. if(n%2==0)
  86. {
  87. if(co[i].length()%2==0)
  88. {
  89. System.out.print(" "+co[i]+" ");
  90. }
  91. }
  92. else
  93. if(co[i].length()%2!=0)
  94. {
  95. System.out.print(" "+co[i]+" ");
  96. }
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement