jam/InsertDelete

From ggc

Jump to: navigation, search

01 package jam;
02 
03 import wiki.Wiki;
04 /**
05  * All about my application here.
06  @author Jam Jenkins
07  */
08 public class InsertDelete
09 {
10   public static void main(String[] args)
11   {
12     String[] catBox=new String[8];
13     catBox[0]="juniper";
14     catBox[1]="cinnamon";
15     catBox[2]="kitty";
16     catBox[3]="tilly";
17     catBox[4]="garfield";
18     catBox[5]="bob";
19     Wiki.out.println("Cats are: ");
20     for(int i=0; i<catBox.length; i++)
21     {
22       Wiki.out.println("Box "+i+" has "+catBox[i]);
23     }
24 
25     //inserting Steve at index 4
26     Wiki.out.println("Inserting Steve at box 4");
27     String inserted="Steve";
28     for(int i=catBox.length-2; i>=4; i--)
29     {
30       catBox[i+1]=catBox[i];
31     }
32     catBox[4]=inserted;
33 
34     //displaying cats
35     Wiki.out.println("Cats are: ");
36     for(int i=0; i<catBox.length; i++)
37     {
38       Wiki.out.println("Box "+i+" has "+catBox[i]);
39     }
40 
41     //removing Cinnamon from index 1
42     String removed=catBox[1];
43     Wiki.out.println("Removing "+removed+" from box 1");
44     for(int i=1; i<catBox.length-1; i++)
45     {
46       catBox[i]=catBox[i+1];
47     }
48 
49     //displaying cats
50     Wiki.out.println("Cats are: ");
51     for(int i=0; i<catBox.length; i++)
52     {
53       Wiki.out.println("Box "+i+" has "+catBox[i]);
54     }
55   }
56 }


Download/View jam/InsertDelete.java





Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter