Important question about my code

Okay so here's the deal, I have been working on creating the 6/49 lottery game and so far everything works fine, however I have one problem with how the program runs.
The instructions are as follows: The program generates 6 random numbers from 1 to 49, then it asks the user to input 6 numbers, and if they guess the generated random numbers they win a prize.
This is where the problem's at, the program generates 6 random numbers, let's say for this topic's sake : 1,2,3,4,5,6. Now if the user inputs let's say 12,34,56,6,9,11 the program should say 1/6 correct since the user guessed the number 6. However since the user entered 6 as the 4th number, it says that the user has gotten 0/6 correct!
Tell me what I'm doing wrong here please... here's my code.
import java.util.Random;
import javax.swing.*;
import java.util.*;
public class GameBeta
     public static void main (String args[])     
          mGame();
     }//end main
public static void mGame()
          Random randomNumbers = new Random();
            String sInput,
                      win = "";
          int iNumber=0,
                match=0,
          randNumber,
          prize=0;
int array [] = new int [50];
     for (int i=1; i<=6; i++)
               randNumber = 1 + randomNumbers.nextInt(49);
               array [randNumber] = randNumber;
                         try
               //get the numbers from the user
               sInput=JOptionPane.showInputDialog ("Enter winning number");
               //convert strings to integers
              iNumber=Integer.parseInt(sInput);
               catch (NumberFormatException nfe)
                    System.out.println ("Invalid input please try again");
                    System.exit (0);
              }//end catch
               if (match==3)
                    prize = 10;
                    if (match==4)
                         prize = 1000;
                         if (match==5)
                              prize = 10000;
                              if (match==6)
                                   prize = 1000000;
          for ( int counter = 1; counter < array.length; counter ++)
                  if (counter % 7 == 0)
                            System.out.printf("%s\n", array [counter]);
                 else
                        System.out.printf("%s ",  array [counter]); 
     System.out.println ("You have got: " + match + " correct answers!");
}//end class Assignment1

Is there a specific reason your using a static method to run your app?
I modified your code slightly so that it will run as a app and you shouldn't get the cannot access non-static method from a static context...
    public static void main(String args[])
        GameBeta gm = new GameBeta();  // create a new instance of your game
        gm.mGame();  //  run the game
        gm = null;  // release the object to gc
        System.exit(0);  //  exit gracefully
    }//end main
    public void mGame() {
    //  the rest of your code....I hope it gives you some insight..
J

Similar Messages

  • Some question about sql code

    for example:
    select
    from testtable
    outputs below results:
    item_desc
    950gapple(z)110ml*40
    650gbanana(z)215ml 1x18
    make above example outputs below result:
    item_desc
    a950gapplez110ml40
    a650gbananaz215ml1x18
    how to write above sql code?
    who can help me?
    thanks

    Jameel Provided solution to one of your other thread
    a question about sql code
    Try the below query. You can modify the TRANSLATE function to add the characters you want to remove from the string.
    select 'a'||replace(translate(str,'()* ','`'),'`') from testtable

  • 3 important questions about SAP HANA

    Hello Community!
    I have got 3 important questions about SAP HANA.
    1.
    - Our Company has all up about 150 SAP - Systems.
    - 12 Systems are ERP-Systems.
    => We consider about SAP HANA at the moment.
    => Is it possible to put all the 12 ERP-Systems in ONE SAP HANA or do I need one seperate HANA for each ERP-System?
    => If it is possible, can you tell me the disadvantages when I use 1 HANA for the 12 ERP-Systems.
    => Is there a Storage-Limit in the HANA (I think no, because of 64 bit).
    => Can I still make realtime-analytics with 1 HANA for 12 SAP Systems?
    2.
    => Can I run ONE HANA with different non-SAP-Systems?
    3.
    => Is there a Demo-Center from SAP or IBM, where I can test and see the HANA before I buy it?
         (I do not mean the Fujitsu TDS Demo Center)
    It would be nice, when you would answer all my questions.
    Thank you.

    I have got 3 important questions about SAP HANA.
    1.
    - Our Company has all up about 150 SAP - Systems.
    - 12 Systems are ERP-Systems.
    => We consider about SAP HANA at the moment.
    => Is it possible to put all the 12 ERP-Systems in ONE SAP HANA or do I need one seperate HANA for each ERP-System? Yes it is quite possible to put all the ERP/CRM/SCM or other components on one HANA. You need to check for pricing/users/RAM (storage)
    => If it is possible, can you tell me the disadvantages when I use 1 HANA for the 12 ERP-Systems.
    There are no disadvantages as of now.. improve existing planning, forecasting, pricing
    optimization and other processes
    => Is there a Storage-Limit in the HANA (I think no, because of 64 bit).
    There is no limit on Stotrage: You need check how much Data you need on RAM (Real time processing) Storage.Minimum you can buy is 64 GB and multiple of it for (RAM)
    => Can I still make realtime-analytics with 1 HANA for 12 SAP Systems?
    Yes certainly..
    2.
    => Can I run ONE HANA with different non-SAP-Systems?
    YEs you can run HANA for 3rd party S/W or non-sap systems for your real time anlytics.
    It has ODBC and JDBC both and you can combine it with other systems.
    3.
    => Is there a Demo-Center from SAP or IBM, where I can test and see the HANA before I buy it?
    (I do not mean the Fujitsu TDS Demo Center)
    This you need to check with your local SAP Service channel..
    It would be nice, when you would answer all my questions.
    Thank you.
    PY

  • Ucs question about major code F0283 and dce interfac and chassis number?

    dear,
    Introductions:
    one 6120 connect  chassis 1 one 2104-1 and   chassis 2 one 2104-1
    chassis 1 have sever 3/4/5/6/7/8  (all sever is B200 M3,two 2104)
    chassis 2 have sever 1/2/3/4/5/7 (sever 1/2/3/4 is B200 M3,two 2104)
    question
    1.major code F0283
    all server have  major code F0283 ,but all sever  still can use.what this? How I did it?
    affected object:sys/chassis-1/blade-6/fabric-A/path-1/vc-722
    description: ether vif 1/6 a-722 down,reason: unknown
    chassis 1 have sever 3/4/5/6/7/8
    chassis 2 have sever 1/2/3/4/5/7
    i shutdown all ,and start the problem is also.
    affected 
    i shutdown all ,and start the problem is also.
    2.on chassis 1 sever-1 adapter 1 dce interface (dce interfac 1 and dce interface 5)
    ony one use? 
    3.
    chassis 1 have sever 3/4/5/6/7/8
    chassis 2 have sever 1/2/3/4/5/7
    but i reboot ,
    chassis 2 have sever 3/4/5/6/7/8
    chassis 1 have sever 1/2/3/4/5/7
    so the profile is disorder
    i shtdown all,and start chassis 1 ok ,later chassis 2
    the problem is ok..what this ?

    Hi Hailing,
    The transport VIF for server is down.The Cisco UCS Manager raises this fault when any of the following scenario occur:
    •Endpoint(switch/fabric  interconnect) reports the connectivity state on virtual interface as  one of: a.down, b.errored, c.unavailable.
    Verify  that the blade discovery was completed successfully. Check the states  on all of the communicating ports in an end to end manner.
    If connectivity seems correct, recommision the server.
    Also, please make sure you are using the correct drivers of the OS installed in the server as Padma recommended you.
    I hope this helps.
    David

  • LAST QUESTION ABOUT MY CODE (promise)

    Here is my final code for the 6/49 lottery game (it's a more simplified version so don't mind that there is no Bonus Number) sorry for the long code...
    I'll just post my question here for those who don't want to go through all of this.
    I want to throw an exception and let it catch it after the first input box appears. So let's say I entered text or a null value in the first input box then it would loop back to the beginning of the program and output a message saying "You entered a wrong value!"
    But in the code that I have, even if I enter text or just press enter without inputting anything, it just moves on to the next input box, until on the 6th input box it says "invalid value".
    So how would I proceed in doing this?
    THANKS!
    import java.util.Random;
    import javax.swing.*;
    public class Game
         public static void main (String args[])     
              mGame();
         }//end main
         public static void mGame()
              JOptionPane.showMessageDialog(null, "Ali Uz\n110231263", "About", JOptionPane.PLAIN_MESSAGE);
              Random randomNumbers = new Random();
              String sInput,
                      win = "";
              int iNumber1=0,
                   iNumber2=0,
                   iNumber3=0,
                   iNumber4=0,
                   iNumber5=0,
                   iNumber6=0,
                   match=0,
                   randNumber,
                   prize=0;
             int array [] = new int [50];
              try
                        //get the numbers from the user
                        sInput=JOptionPane.showInputDialog ("Enter winning number 1.");
                        sInput=JOptionPane.showInputDialog ("Enter winning number 2.");
                        sInput=JOptionPane.showInputDialog ("Enter winning number 3.");
                        sInput=JOptionPane.showInputDialog ("Enter winning number 4.");
                        sInput=JOptionPane.showInputDialog ("Enter winning number 5.");
                        sInput=JOptionPane.showInputDialog ("Enter winning number 6.");
                        //convert strings to integers
                        iNumber1=Integer.parseInt(sInput);
                        iNumber2=Integer.parseInt(sInput);
                        iNumber3=Integer.parseInt(sInput);
                        iNumber4=Integer.parseInt(sInput);
                        iNumber5=Integer.parseInt(sInput);
                        iNumber6=Integer.parseInt(sInput);
             }//end try
              catch (Exception e)
                        System.out.println ("Invalid input please try again");
                        System.exit (0);
              }//end catch
              for (int i=1; i<=6; i++)
                   randNumber = 1 + randomNumbers.nextInt(49);
                   array [randNumber] = randNumber;
                   if (randNumber==iNumber1)
                             match++;
                   else
                             if (randNumber==iNumber2)
                                       match++;
                             else
                                       if (randNumber==iNumber3)
                                                 match++;
                                       else
                                                 if (randNumber==iNumber4)
                                                           match++;
                                                 else
                                                           if (randNumber==iNumber5)
                                                                     match++;
                                                           else
                                                                     if (randNumber==iNumber6)
                                                                               match++;
                   if (match==3)
                        prize = 10;
                        if (match==4)
                             prize = 1000;
                             if (match==5)
                                  prize = 10000;
                                  if (match==6)
                                       prize = 1000000;
              for ( int counter = 1; counter < array.length; counter ++)
                      if (counter % 7 == 0)
                                System.out.printf("%s\n", array [counter]);
                     else
                            System.out.printf("%s ",  array [counter]); 
                   if (match >= 3)
                             System.out.println ("You have gotten " + match + "/6 correct\nYou have won $" + prize);
                   else
                             System.out.println ("You have gotten " + match + "/6 correct\nSorry you have lost! Please try again");     
    }//end class Assignment1

    Your problem here as that the exception you want to
    throw takes place here
    iNumber1=Integer.parseInt(sInput);
    public void showMessage(int number){
    try{
    sInput=JOptionPane.showInputDialog ("Enter
    nter winning number " + number);
    iNumber1=Integer.parseInt(sInput);
    }catch(Exception e){
    System.out.println ("Invalid input please try
    e try again");
    System.exit (0);
    }then call this method from inside a for loop:
    for(int i=1; i <=6; i++){
    showMessage(i);
    }Hope that helps you a littleOnly catch NumberFormatException there, though.

  • Quick Question About Javascript Code

    I'm trying to write some code in JavaScript so that a different image will display every time someone loads my homepage. I have come across a section called
    'imgct' what does "ct" stand for?
    Please excuse the stupid question but this is my first time!
    If anyone could point me in the right direction of how to do this aswell I would be extremely grateful!
    Thanks
    Kyra

    I'm so sorry about this, it just doesn't seem to be working, I did what you suggested but it still doesn't show up in my browser. :S
    The is the code view of my page now:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    <link href="Style_sheet.css" rel="stylesheet" type="text/css" />
    <script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    homeImg = newArray(
    "Images/Homepage/Image1.jpg",
    "Images/Homepage/Image2.jpg",
    "Images/Homepage/Image3.jpg",
    "Images/Homepage/Image4.jpg",
    "Images/Homepage/Image5.jpg"
    ImgCt=homeImg.length;
    function swapImg() {
        if (document.images) {
            randomNum=Math.floor((Mathrandom()*ImgCt));
            document.images ["homePicture"].src = homeImg[randomNum];
    window.onload = swapImg()
    </script>
    </head> 
    <body>
    <div class="container">
      <div class="header">
    *//There is a spry menu bar that goes here//*
        <!-- end .header --></div>
      <div class="content">
      <img src="" name="homePicture" width="627" height="250" id="homePicture" /> </div>
      <noscript><img src="Images/Homepage/Image2.jpg"/></noscript>
    As you can see I have also tried to add in a 'noscript' tag incase someone doesn't have javascript enabled etc. although when I preview it in IE I see both 'Image2' and the image placholder where teh random image is meant to appear, but doesn't.
    I'm very grateful for all the help you are giving me!
    Thank you
    Kyra

  • Some important question about JPA!!!

    Hi there, I have a web application written in Java 1.4
    I want to move this to Java 1.5 using JPA but after review old code I've got some stuck:
    1. This application have a function that get Lists from a table:
    Collection getList(String className, string tableName)
    That do follwing tasks:
    Get set of properties from class schema (by className)
    Get record set from table
    Each row of record set do:
    - Create object and set properties value from column that named the same name of property.
    - Add object to collection
    Return collection
    As my knowledge, in JPA, each entity class schema is mapped with a table schema. So, this function can't migrate. But in my application case, there are about 50 tables, mapping entities to each table is not good idea. Is there another solution?
    2. In database design, a table have composite PKs that merge from many part, each part is a property of entity too, for example table User have column User_ID = Agency_ID + Deparment_ID + SeqNum. How I can map Agency and Department properties of User entity to the table User?
    Please help me, thanks
    Thank you.

    Hi uvnet,
    I think the old code can run in java 1.5 with a minor change but the problem is I want take advantage of using 1.5 especially JPA (big change :D ).
    Anyway, the sample code would be:
    import java.sql.ResultSet;
    import java.util.ArrayList;
    import java.util.Collection;
    import java.util.Iterator;
    import java.util.Map;
    import org.apache.commons.beanutils.BeanUtils;
    import org.apache.commons.beanutils.PropertyUtils;
    public class DAO {
         public Collection getList(String className, String tableName, int encoding) {
              Object objDescriber = null;          
              ResultSet rs = null;
              Map map = null;
              Iterator properties = null;
              ArrayList<Object> returnValue = new ArrayList<Object>();
              try {
                   objDescriber = (Object)Class.forName(className).newInstance();
                   try {
                        map = BeanUtils.describe(objDescriber);
                        properties = map.keySet().iterator();
                        //Get ResultSet from Table
                        rs = getResultSet(tableName);
                        while (rs.next()) {
                             while (properties.hasNext()) {
                                  String name = (String) properties.next();
                                  String typeName = PropertyUtils.getPropertyType(objDescriber, name).getName();
                                  //Get value from current row and column name of ResultSet
                                  Object value = getValue(rs, name, encoding);
                                  try {
                                       Object obj = (Object)Class.forName(className).newInstance();
                                       PropertyUtils.setProperty(obj, typeName, value);
                                       returnValue.add(obj);
                                  catch (Exception ex) {
                   catch (Exception ex) {
              catch (Exception ex) {
              return returnValue;
    }

  • A very important question about the HostSample-Help needed!

    Hi,
    I'm trying to build a plugin for EM 12c ( 12.1.0.2 ) which suppose to monitor jmx mbeans .
    I encountered during the README file which was packed with the EDK .
    1. In the section where I try to use Flash builder ( ver 4.6 - that's the only release I found .. ) I folowed the instructions if how to run the example ( HostSample/HostSystem ) . When I run the example ( I installed the sdk's of Flash and everything that was written there - no problem )
    in the web browser i got the login page , and put the parameters ( username, password ) as it said in the README - the same username/password as i log in to the EM console .Than I got an error saying " ... RPC fault string ..... Logging to management server ... URL:https.. host ( my host name ) : port ( my port number ) /em..."
    Does anyone has a clue about this ? What am i doing wrong or miss something ?
    It is very important and urgent to me . please help .

    To add a bit more detail. Before you run the application from FlashBuilder, open the same browser you will use to run/debug the application in FlashBuilder and install certificate.
    Firefox:
    . when the "This Connection is Untrusted" warning appears
    . expand the "I Understand the Risks" item
    . click the "Add Exception..." button
    . on the "Add Security Exception" dialog, ensure "Permanently store this exception" is checked
    . click "Confirm Security Exception" button
    IE:
    . when the "Certificate Error: Navigation Blocked" page appears, click "Continue to this website (not recommended)"
    . click on the "Certificate Error" icon in the browser address bar
    . in the "Untrusted Certificates" popup, click "View Certificates"
    . click on the "Certification Path" tab of the "Certificate" dialog
    . select the root certificate (certificate at the root of the tree)
    . click "View Certificate..." button
    . click "Install Certificate..." on the "Certificate" dialog that appears
    . click "Next" on the "Certificate Import Wizard"
    . select "Place all certificates in the following store" button and click "Browse..."
    . select "Trusted Root Certification Authorities" on the "Select Certificate Stores" dialog and click "OK"
    . click "Next" button, and then "Finish" button
    . click "Yes" on "Security Warning" dialog that appears
    The other alternative is to enable http access using "emctl secure unlock". This is not recommended for a production site.
    .

  • Important Question About Moving Files

    Aloha DW Community
    I need help/confirmation on this before i do it. I have
    inherrited the website from hell; that meaning the folders on my
    computer and on the server are very unorganized. There are images
    all over the place, in places they just should not be stored. i am
    getting ready to switch to a new service provider for the site so i
    want to start as fresh as possible. i have already downloaded the
    whole site from the server to my local computer. i have gone
    through and deleted all the old files that are no longer needed.
    now before i upload this site to the new server i want to collect
    all the images that are spread about and place them in the same
    folder. my question is this - if i gather all the images together
    and upload the site, will dreamweaver correct all the link paqths
    that have been switched around by me moving all the pictures? i
    know DW does this, but i am not sure if it will do it on such a
    large scale.
    if you know the answer, please let me know.
    thank you in advance
    all the best to you
    e~

    Do all of your organizational moves within DW's Files panel.
    You should be
    fine.
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "sinewave zero" <[email protected]> wrote in
    message
    news:fcf30e$s5h$[email protected]..
    > Aloha DW Community
    >
    > I need help/confirmation on this before i do it. I have
    inherrited the
    > website
    > from hell; that meaning the folders on my computer and
    on the server are
    > very
    > unorganized. There are images all over the place, in
    places they just
    > should
    > not be stored. i am getting ready to switch to a new
    service provider for
    > the
    > site so i want to start as fresh as possible. i have
    already downloaded
    > the
    > whole site from the server to my local computer. i have
    gone through and
    > deleted all the old files that are no longer needed. now
    before i upload
    > this
    > site to the new server i want to collect all the images
    that are spread
    > about
    > and place them in the same folder. my question is this -
    if i gather all
    > the
    > images together and upload the site, will dreamweaver
    correct all the link
    > paqths that have been switched around by me moving all
    the pictures? i
    > know DW
    > does this, but i am not sure if it will do it on such a
    large scale.
    >
    > if you know the answer, please let me know.
    >
    > thank you in advance
    >
    > all the best to you
    >
    > e~
    >

  • Vim newbie question about formatting code

    I just started learning vim and am wondering how I can get it to auto format some code.  For example:
    check() {
    for i in $nodes; do
    ping -c 1 $i > /dev/null
    if [ $? -eq 0 ]; then
    echo "Looks like $i is up so initializing the cluster on it."
    ssh $i "\$HOME/bin/cluster-setup.sh"
    fi
    done
    I have tabstop=3 in my ~/.vimrc and I'd just like to apply formatting to that code block so it looks like:
    check() {
    for i in $nodes; do
    ping -c 1 $i > /dev/null
    if [ $? -eq 0 ]; then
    echo "Looks like $i is up so initializing the cluster on it."
    ssh $i "\$HOME/bin/cluster-setup.sh"
    fi
    done
    I read about =i{ but it has no effect for me.
    Thanks!
    Last edited by graysky (2011-06-18 14:32:18)

    graysky,
    If you want vim to autoindent while typing, customize your ~/.vimrc file. I posted mine here: http://linuxandsuch.wordpress.com/2011/06/19/my-vimrc/ a few days back. I recommend all the options.
    However, if you want to indent an already existing file use the indent program. Install with
    sudo pacman -S indent
    And then, to indent your file, run:
    indent myfile.c
    I'd recommend reading the manpage for indent to learn to tweak it to your coding style though .

  • Question about error code

    I have been having problems when I try to open applications such as IPhotos or Photoshop. They keep on quitting. I did the Hardware Test and it showed error code 2MEM/5/4:DIMM1/J31. Does anyone know what it means and what I should do? I do not have a warranty anymore and now I wondered if I am gonna have to get the coverage plan (my budget is tight right now). Thank you for any help you can give me.

    Either the module has failed or has come loose. At this time I'd open up your computer and make sure it's still locked in place. Afterwards, no need to run the hardware test, just check with System Profiler to see if you were able to nudge it back into position.
    Once in a while RAM modules do fail, but not very often.
    Edit-
    Since you apparently did not purchase this from Apple, it probably is still under lifetime warranty by the seller, so look up your original order number on the invoice and fill out an RMA request on the website of your supplier, or of the manufacturer (brand) itself. If they don't have a Support section or warranty or RMA section, you'll have to email them.
    Put off thinking about eBay until you find out if it will be replaced under warranty.
    [If you had an extra 1GB of memory, that is not going to be a bargain on eBay, as many are just now upgrading and trying to buy that size, but if you had an extra 512MB, then that is what can be found for a fraction of the price you'd have to pay for new anywhere else. If you're really lucky you can find someone with a relatively new iBook or PowerBook who might be looking to sell what hardly had any use. Caution in shipping is required, as the biggest cause of RAM failure is mishandling of the module between manufacture and packaging.]

  • Question about Byte Code

    Hello...can anyone tell me how I write a java program, compile it and get my byte code written into another file??
    Thanks in advance!

    I am looking to write my bytecode into a .bc file and
    open it and actually be able to read the bytecode
    instruction...(stuff like iload_2, i2d etc.,)I see... that was not clear from your first question. What you want is a disassembler. The SDK comes with one called 'javap': http://java.sun.com/j2se/1.4.1/docs/tooldocs/windows/javap.html

  • Important Question About N95 New FirmWare?

    Hi,
    I need to ask about the updating of the new firmware for n95...
    while i am updating if :
    *the PC shutdown
    *someone call me and the mobile ring at the updating process
    *the electricity went off
    *the internet connection have a problem
    *the battery become empty at the updating process
    WHAT Will Happen to The Phone????
    somebody says its over,the mobile is gone,its damaged
    &the REAL QUESTION HERE IS :
    Can i just restart the process from the begining or what?
    &Does the Backup process that i had done it at the PC is useful to get back the old Firmware or its just for the files i installed on the phone??
    thx gus.............

    while i am updating if : ... see here
    http://europe.nokia.com/A4577229
    *the PC shutdown
    - you should get "Software update failed".
    *someone call me and the mobile ring at the updating process
    - calls can be made and received while the software is being downloaded. The call will be terminated automatically when the update phase begins.
    *the electricity went off/*the internet connection have a problem/*the battery become empty at the updating process
    - Power or internet connection was lost during the update. The update may have been successful. Remove the battery and if the software was not updated, try again.
    *Does the Backup process that i had done it at the PC is useful to get back the old Firmware or its just for the files i installed on the phone??
    - Nokia device firmware cannot be downgraded. Once you have upgraded your device, you will not be able to restore it to the earlier version.

  • Question about error-code in web.xml

    Can you use pattern matching for error-codes?
    Instead of
    <error-code>401</error-code>
    <error-code>403</error-code>
    <error-code>404</error-code>
    etc..
    you could just do
    <error-code>4*</error-code>

    I don't know a replacement for this, but I recommend to post this questione into Servlets section to get more chances for receiving answers...
    Regards,
    Mohammed Saleem

  • Questions about byte code

    1.How can a java program mutate and kill itself after running a certain times?
    i think the argorithm is to modify the byte code, but i don't know the structure of the byte code.
    for example:
    "int i=1156;
    victim.seek(i);
    int changed_byte=(int)victim.readUnsignedByte()+1;
    victim.seek(i);
    victim.writeByte(changed_byte);"
    how can i know that 1156 is the place that count the running times of the program. please help me and give the relevent pages to read, many thanks!

    In Mustang, the java.lang.instrument API has been extended to allow not only redefinition of classes, but also retransformation (without / with original bytes, respectively), so you could hook up a Java agent to transform classes at will. You could use this with 5.0, but you can't get the actual bytes for the current class from the JVM when retransforming classes. See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/instrument/package-summary.html#package_description and http://download.java.net/jdk6/docs/api/java/lang/instrument/package-summary.html#package_description for more on instrumentation in 5.0 and (provisionally) 6.0.
    You might find a tool I've been working on lately useful: http://jen.dev.java.net/ - It basically presents a mutable class with a collections-ish interface and allows you to generate as bytes or a Class. It can be used in regular code, in agents, with .class files, byte arrays, java.lang.Classes, and so on.
    However, I would question your motivation here, particularly since you're using names like 'victim' and 'attacker'. You will struggle to do any of this is the user really doesn't want you to, since the platform is designed pretty well against it.

Maybe you are looking for