454,653 Members | 1,483 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,653 IT Pros & Developers. It's quick & easy.

# For Loop and Arraylist

 P: 2 I need help here because i dont know how to take the last Number from the Arraylist away that i wrote in it. (And i dont know how to make it that he doesnt go in else after i pressed "a". Expand|Select|Wrap|Line Numbers import java.math.BigInteger; import java.util.*; import java.io.IOException; public class stack  {       public static void main(String[] args)      {         Scanner s = new Scanner(System.in);         ArrayList al = new ArrayList();         Integer i = 0;         for(int zahl=2; zahl>1;zahl++ )         {         System.out.println(al);         System.out.println("Geben sie bitte (a) für's hinzufügen einer Zahl und (b) für's abziehen der letzten Zahl ein:");         String eingabe = s.nextLine();             if (eingabe.equals("a"))         {               System.out.println("Was für eine Zahl möchten sie hinzufügen?:");             i = s.nextInt();             al.add(i);           }         else if (eingabe.equals("b"))         {           }         }     } }   Oct 18 '12 #1
2 Replies

 Expert Mod 10K+ P: 12,421 The size method will give you the number of elements in the array. You can use that to pull the last element inserted using the index. As for your second question, I don't understand what you said. Oct 18 '12 #2

 P: 2 Thank you but we solved the problem with some other developers. :) Oct 19 '12 #3