Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java Problem for real java programmer
#5
Code:
import javax.swing.JOptionPane;

public class Test2
{
    public static void main (String [] args)
    {

        String inp;
        int cho, input, index;
        int [] number = new int [10];
                input=index=0;            
      
      
      
    do
    {              
              
    inp=JOptionPane.showInputDialog(" Choose number: \n1. Push    \n2. Pop\n 3. Display\n 4. Exit ");
    cho =Integer.parseInt(inp);

    if (cho == 1)
        {
            if (input<10)
            {  
              
                inp=JOptionPane.showInputDialog("Index "+ (input)+(" of 9:"),"");
                number[input]=Integer.parseInt(inp);
                input++;  
              
                JOptionPane.showMessageDialog(null,"                Updated!","Update Message",JOptionPane.INFORMATION_MESSAGE);              
            }
            else
            {
                JOptionPane.showMessageDialog(null," Full\n ","Overflow",JOptionPane.ERROR_MESSAGE);
            }
                  
                              
          
                  
        }
      
    else if (cho==2)
        {
            if (number [0]==0)
            {
                JOptionPane.showMessageDialog(null,"        Input at least 1 first before pressing 2","No Stack",JOptionPane.ERROR_MESSAGE);
            }
      

            else
            {
                number[input-1]=0;
                input--;
              
                JOptionPane.showMessageDialog(null,"                Updated!","Update Message",JOptionPane.INFORMATION_MESSAGE);              
            }
        }  
  
    else if (cho==3)
        {
                    System.out.print("STACK: ");  
      
        for (index=0; index<=9; index++)
            {
              
          
                System.out.print("||"+number[index]+"|| ");
          
          
            }
          
          
                System.out.print("\n");
                System.out.print("INDEX: ");
          
        for (index=0;index<=9;index++)
            {
                System.out.print("||"+index+"|| ");
            }
          
            System.out.print("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
        }
  
    else if (cho==4)
        {
            JOptionPane.showMessageDialog(null,"                Exit!");
        }
  
  
    else
        {
            JOptionPane.showMessageDialog(null,"               Invalid Input!");
        }  
      
      
                System.out.print("S T A C K:\n");  
      
        for (index=0; index<=9; index++)
            {
                System.out.print("||  "+number[index]+"  \n");
            }
          
              
                System.out.print("\n");
          
          
                System.out.print("I N D E X:\n");  
      
        for (index=0; index<=9; index++)
            {              
            System.out.print("||  "+index+"\n");
            }
          
            System.out.print("\n");
          
      
    }
  
    while(cho!=4);
          
    }
}
this is the code,... before,. but in the last day at the school i do some modification here, like removing some text to make it clean,..
Reply


Messages In This Thread
RE: Java Problem for real java programmer - by Testgamma1 - 12-26-2009, 05:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sam's Teach Yourself Java in 21 Days? Grizzly 22 10,130 04-16-2019, 09:39 AM
Last Post: joeywilliams
  Beginning Java Miku 2 1,458 07-25-2017, 01:19 AM
Last Post: byteshubb
  Minecraft in java. Denny Crane 12 3,757 11-05-2012, 03:55 PM
Last Post: Nickelodeon
  java GUI ? prince76 8 3,034 03-22-2012, 08:55 AM
Last Post: redpois0n
  [ Java Tutorials and Guides ] prince76 7 1,994 02-28-2012, 09:34 AM
Last Post: ven0m

Forum Jump:


Users browsing this thread: 1 Guest(s)