Advertisement
Svetlana_Ovsjanikova

java - MoreLists.tasks

Sep 21st, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 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 day6_morelists;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author sao_7
  14. */
  15. public class tasks {
  16.  
  17. Scanner sc = new Scanner(System.in);
  18. String choice = "";
  19.  
  20.  
  21.  
  22. public static void getAddLists() {
  23. Scanner sc = new Scanner(System.in);
  24. String choice = "";
  25.  
  26. ArrayList<String> listOfStrings = new ArrayList<String>();
  27. do {
  28. System.out.println("Ievadiet jaunu vertibu ");
  29. String input = sc.nextLine();
  30. listOfStrings.add(input);
  31.  
  32. outputList(listOfStrings);
  33.  
  34. System.out.println("Vai velaties turpinat, ja ne rakstat exit ");
  35. choice = sc.next();
  36.  
  37.  
  38. for (int i = 0; i < listOfStrings.size(); i++) {
  39. System.out.println(listOfStrings.get(i));
  40. }
  41.  
  42. } while (!choice.equals("exit"));
  43. }
  44.  
  45. public static void removeFromList(ArrayList<String>parList){
  46. Scanner sc = new Scanner(System.in);
  47. if (sc.hasNextInt()) {
  48. int index = sc.nextInt();
  49. if (index > -1 && index < parList.size()) {
  50. parList.remove(index);
  51. }else
  52. System.out.println("Nekorekta ievade");
  53. }
  54.  
  55. }
  56.  
  57. public static void outputList(ArrayList<String> parList) {
  58. System.out.println("Saraksts: ");
  59. for (int i = 0; i < parList.size(); i++) {
  60. System.out.println("1) " + parList.get(i) + "");
  61. }
  62. }
  63. //1) izvadit sarakstu
  64. //2) pievienot jaunu elementu
  65. //3) dzest elementu
  66. //4) rediget elementi (pec indeksa)
  67. //5) iziet no programmas
  68.  
  69. //String list
  70. //Validacija - .isEmptty() metode
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement