Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package day6_morelists;
- import java.util.ArrayList;
- import java.util.Scanner;
- /**
- *
- * @author sao_7
- */
- public class tasks {
- Scanner sc = new Scanner(System.in);
- String choice = "";
- public static void getAddLists() {
- Scanner sc = new Scanner(System.in);
- String choice = "";
- ArrayList<String> listOfStrings = new ArrayList<String>();
- do {
- System.out.println("Ievadiet jaunu vertibu ");
- String input = sc.nextLine();
- listOfStrings.add(input);
- outputList(listOfStrings);
- System.out.println("Vai velaties turpinat, ja ne rakstat exit ");
- choice = sc.next();
- for (int i = 0; i < listOfStrings.size(); i++) {
- System.out.println(listOfStrings.get(i));
- }
- } while (!choice.equals("exit"));
- }
- public static void removeFromList(ArrayList<String>parList){
- Scanner sc = new Scanner(System.in);
- if (sc.hasNextInt()) {
- int index = sc.nextInt();
- if (index > -1 && index < parList.size()) {
- parList.remove(index);
- }else
- System.out.println("Nekorekta ievade");
- }
- }
- public static void outputList(ArrayList<String> parList) {
- System.out.println("Saraksts: ");
- for (int i = 0; i < parList.size(); i++) {
- System.out.println("1) " + parList.get(i) + "");
- }
- }
- //1) izvadit sarakstu
- //2) pievienot jaunu elementu
- //3) dzest elementu
- //4) rediget elementi (pec indeksa)
- //5) iziet no programmas
- //String list
- //Validacija - .isEmptty() metode
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement