473,326 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

For Loop and Arraylist

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
2 1732
Rabbit
12,516 Expert Mod 8TB
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
Thank you but we solved the problem with some other developers. :)
Oct 19 '12 #3

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

Similar topics

10
by: Eric | last post by:
I'm looking at this page in the MSDN right here: ms-help://MS.MSDNQTR.2003FEB.1033/cpref/html/frlrfsystemcollectionsarraylist classsynchronizedtopic2.htm (or online here:...
5
by: David C | last post by:
This is very strange. Say I have code like this. I am simply looping through a collection object in a foreach loop. Course course = new Course(); foreach(Student s in course.Students) {...
4
by: tma | last post by:
I'm trying to save code to a session object like the following: dim oAppList as arraylist dim oApp as someclass Code to manipulate oApp... .... .... oApplist.Add(oApp)...
4
by: Mike | last post by:
I have declared two classes. The first class has 4 private variables. Each has a property defined. I'm calling a readfile sub from a second class. The second class also has an Arraylist...
4
by: blisspikle | last post by:
The following sub form1_load reads in a text file that will say something like the text below. I think that the problem is that every time I add a class V_Sensor into the arraylist it puts it in...
5
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim...
9
by: Andreas Schmitt | last post by:
I am somewhat new to C# and I ran into a problem in a small program I am writing for teaching myself. I am handling a list ob objects and I want to delete some of them inside a loop like in: ...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
7
by: Kamran Shafi | last post by:
Hi, I am creating an arraylist (say masterArrayList) of hashtables, where each hashtable (say table) is of the format key=string, value = arraylist of strings (say existing_strings). In a...
32
by: falconsx23 | last post by:
I am making a game called Set, it is a card game: here is a brief description of the rules: The game of Set is played with 81 cards, each of which has 4 properties (number, pattern, color and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.