Random integer that is a multiple of 5?

So far I got the program to tell me if the user's inputted letter is right or wrong, but how can I have the computer tell the user what slot the guessed letter (if correct) is in? I.e. the letter "e" is in the first and last slots.
This is what I have so far, but all it says is the previously used wrong letters and previously guessed right letters, but not in the order of the word.
          JOptionPane.showMessageDialog (null, "You have guessed all of the following letters incorrectly: \n" + guessedWrongLetters + "\n \nYou have guessed all of the following correct letters: \n" + guessedRightLetters);Also, How can I generate a random integer between one and 250 that is a multiple of five? I.e. 5, 10, 15, etc. I'm using the String.substring (+start+, end) method to choose a random word from a single variable "wordlist" that contains 50 five letter words.
This is what I have, but it just chooses at random letter for the first part of the substring, and adds five to that chosen letter for the second part. So it sometimes chooses something in the middle of a word.
compNumOne = 1 + randy.nextInt (245);
           compNumTwo = compNumOne + 5;
           itsComputersWord = itsComputersWordList.substring(compNumOne, compNumTwo);Here is the word list:
     private String itsComputersWordList = "firstbibleshoeshoneyearthgloveapplechildshipsboatsaortaacidsallowroadsburntbusesdocksbucksbuddydudesudderembedemberelveseggedentryebonydunesdoweldozeldoorsdiverdisksdirksdinerdualsfrothelbowfryerfrozefrownfretsfumedgullsneckshairyhabitlinenlilacmedal";}Edited by: Pluberus on Nov 20, 2008 4:17 PM - Fixed a mistake.

Pluberus wrote:
What about something like this:?
                indexHolder = itsComputersWord.indexOf(itsUsersLetter);
if (indexHolder == 0)
JOptionPane.showMessageDialog (null, "The letter you guessed is the first letter of the secret word.");
if (indexHolder == 1)
JOptionPane.showMessageDialog (null, "The letter you guessed is the second letter of the secret word.");
if (indexHolder == 2)
JOptionPane.showMessageDialog (null, "The letter you guessed is the third letter of the secret word.");
if (indexHolder == 3)
JOptionPane.showMessageDialog (null, "The letter you guessed is the fourth letter of the secret word.");               
if (indexHolder == 4)
JOptionPane.showMessageDialog (null, "The letter you guessed is the fifth letter of the secret word.");By the way, is there an easier way to do what I just did? instead of all the multiple ifs?
Also, since none of my words have a letter used 3 times. Could I use the lastIndexOf and the indexOf to tell the user what position their letter is in?Ouch. Are you considering doing that all the way to virtual infinity? Why not just show something like:
"The letter you guessed is in position " + (indexHolder + 1)
instead of converting numbers into english ordinal words. Unless you want to build that complexity into the system as well, for virtually no benefit.
Also, what if the letter isn't found, when indexHolder is -1? You should account for that as well.

Similar Messages

  • Number that is a multiple of 9 and all digits are even?

    I've writen this short program to find a number that is a multiple of 9 yet all its digits are even. Here is the code. I'm sure its not very compact and am doing this the hard way.
    public class alldigitseven
        public static void main(String[] args)
            int number = 0;
            String numberString, tempString;
            char tempChar;
            int tempInt, matches = 0, stringLength;
            double tempRemainder;
            boolean answer = false;
            while (answer != true)
                // add 9 to the number
                if (number < 1000000)
                    number += 9;
                // convert the int to a string
                numberString = "" + number;
                stringLength = numberString.length();
                for (int i = 0; i <= stringLength; i++)
                    tempChar = numberString.charAt(i);
                    tempString = "" + tempChar;
                    tempInt = Integer.parseInt(tempString);
                    tempRemainder = tempInt%2;
                    if (tempRemainder == 0)
                        matches++;
                    if (matches == stringLength - 1)
                        System.out.println (numberString);
                        answer = true;
    }anways the code complies fine however when I run it, I get the error
    "StringIndexOutOfBoundsException:
    String index out of range: 1 (in Java.lang.String)"
    What do I need to do to fix this?

    here was the final code if anyone was curious...
    public class alldigitseven
        public static void main(String[] args)
            int number = 0;
            String numberString, tempString;
            char tempChar;
            int tempInt, matches = 0, stringLength;
            int tempRemainder;
            boolean answer = false;
            while (answer != true)
                // reset matches
                matches = 0;
                // add 9 to the number
                if (number < 1000)
                    number += 9;
                else
                    answer = true;
                // convert the int to a string
                numberString = "" + number;
                stringLength = numberString.length();
                for (int i = 0; i < stringLength; i++)
                    tempChar = numberString.charAt(i);
                    tempString = "" + tempChar;
                    tempInt = Integer.parseInt(tempString);
                    tempRemainder = tempInt%2;
                    if (tempRemainder == 0)
                        matches++;
                    if (matches == stringLength)
                        System.out.println (numberString);
            answer = true;
    }

  • Random Integer - Code help

    Hi, I'm having a bit of a problem with a program I am making for class. I'm not asking you guys to do my work for me, I just simply need some guidance as to what I am doing wrong.
    Alright, what I am suppose to write as a program that takes two user defined integers and then prints a random integer from between the two user numbers. This is the code I have thus far:
            int a = Integer.parseInt(args[0]);
         int b = Integer.parseInt(args[1]);
         double r = Math.random();
         int low = a + (int) (r * a);
         int high = a - (int) (r * b);
         int result = low + high;
         System.out.println(result);For the most part it seems to work, however it will only work if the two user defined numbers are more then 10 digits of each other. I.E. 10 20 will work fine, however 1 5 will not, 10 15, etc.
    Any help would be greatly appreciated!
    Edited by: KnivesACE on Sep 18, 2008 11:32 AM

    Stianbl wrote:
    lower = 1000;  // your lower integer value
    upper = 2000; // the larger one of your two integers
    double rand = Math.random();
    int result = lower + (int)((upper - lower)* rand);
    http://forums.sun.com/thread.jspa?threadID=590266&messageID=3948731
    The question here is whether the two limits are to be included in the random range? In your solution 2000 will never happen. If you want it to it should look like this,
    int result = lower + (int)((upper - lower + 1)* rand);

  • Is it possible to create a configuration profile that will install multiple network printers and their associated drivers

    Is it possible to create a configuration profile that will install multiple network printers and their associated drivers?
    I was not able to find profile manager on my employer's installation of 10.6 Server. Is this only a feature of 10.7/10.8 server?

    10.6 server does not have profile manager, profile manager is only available in 10/7 and 10.8 server
    for 10.6 server you'll need to use wgm and server admin
    printer management with 10.6, I recommend you read the relevant server manuals regarding
    print server and user management, printer management

  • Hi - When I go into Contacts and type a letter in the search bar to get to last names that begin with that letter I get a list of random names that don't correlate to the letter. My settings are fine.  Help ?

    Hi. When I go into my contacts and type a letter in the saerch bar to get to a list of last names that begin with that letter I get a list of random names that don't begin or end with the letter.  My Settings appear fine.  Any insights would be greatly appreciated.  Cheers Bill

    The search bar is not designed to take you to names beginning with the letter you put in. If you want to do that, use the letters down the side. In the search bar, the device will return results for all contacts that have that have that letter in them. If you type a couple of letters of the name, you'll find what you want faster. Once you get used to how it works, it's quite efficient.
    Best of luck.

  • Can I create a PDF fillable form that allows form multiple entries and one submission?

    For example, I would like to enter new hire information for multiple new hire employees and only click the submit button once.

    Good Morning Randy -
    Sorry for not giving you a clear enough description. I was trying to avoid a novel.
    I hope to use FORMSCENTRAL for create a form for on-line users to register for meetings including paying via paypal.  Some of the people register and pay for the meeting by themselves and others are registered by their office assistant, so there might be as many as 25-30 people.
    The individual registrants are easy and doable with FORMSCENTRAL.
    However, for the multiple registrants, I would like to create a form that can handle multiple registrants and only one submission for payment.  So far, I have  only been able to do that by creating a form that has the registrant fields created multiple times.  I would really like to be able to have the set of fields created once unless I need to add the set of fields multiple times.  I am sure that complications keeping track of the total payment due as well.
    Being able to set-up a table with the fields across (left to right) for each registrant would be good.
    Maybe this does not explain it well enough in which case, I can call and explain our need.
    Thanks in advance.
    Paul

  • Need some help archiving and photos that are in multiple collections.

    After creating a new catalog for photos from a collection, I'd want to remove the photos from Lightroom and keep on disk.  In the collection, there are some photos that are in multiple other collections and I'd want to keep those images in their other collections and so not removed them from Lightroom.
    Need some advice on how to easily identlfy those images that are in other collections and thus might not want to remove those images from Lightroom.

    Well, Bob, that works, but agreeing with Geoff, I don't think this is the best solution to the problem; in fact I don't even think this is a good solution to this problem.
    If there isn't a lot of space left, and the user wants to do something about the photos in those collections, then the photos should be moved (in Lightroom, or via this process: http://www.computer-darkroom.com/lr2_find_folder/find-folder.htm) to a different drive. This generates more free space on the SSD drive. The photos remain in the Lightroom catalog, and they remain in the multiple collections that they are in now.
    MrhoniKeith -- your photos probably should not go on the SSD in the first place. Photos ought to be stored on a normal hard drive, not an SSD. You can move them to a regular hard drive en masse, freeing up plenty of space on the SSD via this method: http://www.computer-darkroom.com/lr2_find_folder/find-folder.htm. This is the BEST solution to your problem -- keep everything in a single catalog, with photos on a normal hard disk. The idea of having multiple catalogs to help free up space on one drive works opposite to the best practices of using Lightroom, in which most people recommend using a single catalog for all of your photos, except in special cases where the photo's contents are completely non-overlapping, for example Personal and Business catalogs.
    Removing photos from some collections but not others will NOT free up space. That's not how Lightroom works. Lightroom has not made multiple copies of your photos for each collection. Deleting photos from collections will NOT free up space.

  • How generate a random number that is between 0 and 15! (0-15)

    how generate a random number that is between 0 and 15 ??? (0-15)
    pls tell me, thx!!!!!!!!!!!!!!!!!

    import java.util.Random;
    Random r = new Random();
    int mynumber = r.nextInt()%16;
    For (2^1)-1 number use:
    -> int mynumber = r.nextInt()&15; // speedup

  • My IMac has wavy lines covering the screen that look like multiple miniature calendars and I want to know how to clear them?

    My IMac has wavy lines that look like multiple quotatient marks or tiny calendars that cover the screen. How do I get rid of them?

    Does a command-shift-3 show the information in an image?  If it does, then post it here using this tip:
    https://discussions.apple.com/docs/DOC-6917

  • Trying to set up a group email "RAM" that will contain multiple email addresses.  Receive error messages "check SMTP settings" or "Invalid email address" when I try to send a message to the group.

    I am trying to set up the group email "RAM" that will contain multiple email addresses.  I have inputted the name "RAM" as a corporation.  In the section labeled "Email" I have inputed multiple email addreses so that when I want to send an email to the group "RAM" I just have to input the name "RAM" in the section labeled "To" , input the Subject in the Subject box & the email will be sent to the multiple addresses, yet when I do I receive either one of two error messages being "Invalid Email Address" or "Check SMTP settings" each of which allows me the option of with cancelling the email or send it anyway.

    Bump. I'd like to know, too. I even have some synched Groups from my Apple Address Book I email to using Apple Mail on the Powerbook, but I can't see how to do a group mailing on the Touch either.
    In normal Mail, I just start typing the name of the group, and it autocompletes, I hit return, and it fills in all addresses in the Group.

  • How do I generate an array of random numbers that relate to an output wave that falls within a certain frequency range?

    I have been creating random numbers that I'm using within a system, the system is working fine, but now I have realised that the random numbers must be outputted to speakers in such a way as to filter out all but a low frequency range.
    I was thinking about generating a dither signal with a bandpass filter, but could not get it to give me out a full array of 250 values which I could then manipulate.
    The sampling frequency of the output is 200Hz and the 250 data points must fall within the 0-100Hz range.
    Another course of action I am considering is to use an FFT and an inverse FFT to get the data that I'm looking for, but I'm fair
    ly inexperienced with using labVIEW and can't quite get it to work.
    Thanks for the help,
    Hank.

    As you may already know, in the Functions palette/Analysis VIs/Filters VIs are VIs for filtering. There are also some examples for using these filters under Examples/Analysis/fltrxmpl. You may find some of these are related to your situation, especially for filtering out the higher values.
    An option is to simply output the random values to a Comparison/"less than or equal" function, where only values <= to 100 would be sent to an array which is in a For loop. Use the iteration counter of the For loop to count up to 250, at which time you would pass the whole array to your next node. This would let you have 250 values between 0 and 100 for your final array.
    Good luck.

  • Do Applets that runs in multiple IE use the different JVM?

    I found that it seems that applets that runs in multiple IE or multiple Firefox instance/process
    share the same JVM instance on Windows.
    Is it the same on Linux and other platforms?
    Or it is just a bug relative to this one?
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6587166
    Thanks.

    1. For IE, I enabled java console.
    2. Start one instance of IE with an applet page. Got a console.
    3. Start second instance of IE (double click on it, not New Window!) with an applet page. Got a second console.
    This tells me that the 2 instances do not share the VM.

  • SSAS- DAX expression : Is there any DAX function that can return multiple values ?

    Hi,
    Iam in search of a DAX function that can return multiple values as result. please find below scenario where i want to implement the same.
    I have three  Tables: Table A (typeid, Cost, Qty ) ,Table B (typeid, Cost, Qty ) , Table C ( typeid,Typename ) .
    Table A                                       Table B                               
    Table C
    type id  cost  Qty             type id   Cost    Qty                 
    typeid  typename
    1           100    100                3         300     
    300                  1           aa
    2           200    200                4          400    
    400                  2           bb
                                                                                             3           cc
                                                                                             4          
    dd 
    i have to club cost and Qty of two tables(four measures)  as two measures in the  UI report. There are more columns in these tables that restrict the  UNION of the tables.(for the sake
    of understanding , i have not mentioned the othr columns). In the UI report(Execl 2013-power pivot) iam plotting these measures against the
    Table C.Typeid. Hence the measures drill down against each 
    Table C. Typeid as shown below:
    Typeid  Table A.cost  Table A.Qty  TableB.cost  TableB.Qty                              
    1              100             100
    2              200             200
    3                                                    
    300             300      
    4                                                    
    400             400
    My requirement is to club these measures so that the report will be as below
    Type id  cost   Qty
    1          100    100
    2          200    200
    3         300     300
    4         400      400
    Since i cannot club these in model,as a work around, i created a calculated measure in excel(Analyze tab->Calculations->olap tools->calculated measure) with the condition as below:
    new cost = IIF (ISEMPTY(TableA.cost)="TRUE",TableB.cost,TableA.cost)
    new Qty = IIF(ISEMPTY(TableA.Qty)="TRUE",TableB.Qty,TableA.Qty) and dragged these new measures into the report. It was working fine as expected.
    But  this functionality of Creating calculatedmeasure in excel report is possible only in 2013 excel version.
    Now the requirement is to get the same result in 2010 excel. Can you please help me in implementing the same in 2010 excel? or any other alternative method to bring the columns in model itself. I tried to create a measure in table A with DAX expression as
    : new cost :=CALCULATE(SUM(Table B.cost),ISBLANK(TableA.cost)) -> but this will return only 1 result .i need Sum(Table A.cost) also if it is not blank.
    Thanks in advance

    You can use SUMX ( 'Table A', 'Table A'[Cost] + 'Table B'[cost] )
    However, if you install the latest version of Power Pivot in Excel 2010, it supports the ISEMPTY function, too.
    http://support.microsoft.com/kb/2954099/en-us
    Marco Russo http://www.sqlbi.com http://www.powerpivotworkshop.com http://sqlblog.com/blogs/marco_russo

  • I have a random file that keeps reapering on my mac

    Hi
    I have a random file that keeps reapering on my mac and i cant delete it or it just come back. could somebody help me

    Quit all open applications.
    Command + Option + Esc
    Then restart your Mac.
    See if the file reappears.

  • Global random integer generation in a range

    Hello,
    I need a way to achieve a global random integer generation in a range.
    I tried FMs QF05_RANDOM_INTEGER and RANDOM_I4 without success because every time I call them from an object, always get the same number
    For example, FM RANDOM_I4 with RND_MIN = 1 and RND_MAX = 5 gets RND_VALUE = 1 and FM QF05_RANDOM_INTEGER with RAN_INT_MAX = 5 and AN_INT_MIN = 1 gets RAN_INT = 3.
    How can I get a global (with memory) random number generator?
    Regards and thanks in advance.

    Hey run the code below, it will give you different numbers.
    data RAN_INT like QF00-RAN_INT.
    data G_RAN_SEED like QF00-RAN_SEED.
    CALL FUNCTION 'QF05_RANDOM_INTEGER'
        EXPORTING
             RAN_INT_MAX   = 5
             RAN_INT_MIN   = 1
        IMPORTING
             RAN_INT       = RAN_INT
        EXCEPTIONS
             INVALID_INPUT = 1
             OTHERS        = 2
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    write ran_int.
    G_RAN_SEED = ran_int.
    CALL FUNCTION 'QF05_RANDOM_SAVE_SEED'
        EXPORTING
             RAN_SEED_NEXT = G_RAN_SEED

Maybe you are looking for

  • BI 7.0 - Duplicate Record Error while loading master data

    I am working on BI 7.0 and I am trying to load master data to an info object. I created an Infopackage and loaded into PSA. I created transformation and DTP and I get an error after I execute the DTP about duplicate records. I have read all previous

  • MacBook Pro crashes and I have no idea why :(

    Since yesterday my macbook pro 13" mid 2012 has already crashed two times and it never did that before. The only things I have installed recently are OS X Yosemite and WonTube Free Video converter. Could anyone help me? Ironically I am kind of panick

  • Time Machine is not working for me

    There is no way that Time Machine is working right for me. Backups are taking a split second and are reporting crazy small amounts. Example, I have added to my Mac 1 gig of movies and 1 gig of images. I backed up today and Time Machine reported 28k o

  • Where are the help files? (CS5)

    I am studying CS5 but I can't find help files or tutorials... is everything  online now? Where should I go for help?

  • Certain apps quit unexpectedly

    hello there...i been having this problem for quite some time now and its starting to annoy me. once in a while if i'm using a certain application...for instance safari, it will quit unexpectedly and the message comes up...application quit unexpectedl