By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,653 Members | 1,483 Online
Bytes IT Community
+ 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
  1. import java.math.BigInteger;
  2. import java.util.*;
  3. import java.io.IOException;
  4. public class stack 
  5. {
  6.  
  7.     public static void main(String[] args) 
  8.     {
  9.         Scanner s = new Scanner(System.in);
  10.         ArrayList al = new ArrayList();
  11.         Integer i = 0;
  12.         for(int zahl=2; zahl>1;zahl++ )
  13.         {
  14.         System.out.println(al);
  15.         System.out.println("Geben sie bitte (a) für's hinzufügen einer Zahl und (b) für's abziehen der letzten Zahl ein:");
  16.         String eingabe = s.nextLine();
  17.  
  18.  
  19.         if (eingabe.equals("a"))
  20.         {
  21.  
  22.             System.out.println("Was für eine Zahl möchten sie hinzufügen?:");
  23.             i = s.nextInt();
  24.             al.add(i);
  25.  
  26.         }
  27.         else if (eingabe.equals("b"))
  28.         {
  29.  
  30.         }
  31.         }
  32.     }
  33. }
  34.  
Oct 18 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
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

Post your reply

Sign in to post your reply or Sign up for a free account.