Array Trouble

So I am new to Java, and took my first semester of a java course. It was hard for me at first, but I am slowly improving. My professor posted this as our last assignment for the semester, and I am having trouble with it as it involves arrays. I do not really know where to start, and any help would be greatly appreciated. I will post the assignment below, followed by the small bit of code I have so far. By no means do I want the answers to this, as I actually do enjoy learning, but any type of help, input, suggestions, etc are greatly appreciated. Thanks in advance!
Write a program which prompts the user to input a series of characters, one at a time. The program will stop prompting the user for characters once the user enters an exclamation point ('!').
Using an array, count the number of occurrences of each letter (regardless of whether it is upper or lower case (so for example, an 'A' and an 'a' both count for the first letter of the alphabet). In a separate counter, also count the total number of "other" characters ('.', '?', ' ', '2', etc.). The final exclamation point does not count.
Print out the count for each letter found (but not for those which where not found!)
Print the count of the non-letter characters.
List the characters that were not found (e.g. "The following letters were not found: t, z, c.").
By inspecting the array, print out the total number of all of the vowels, and the total number of all of the consonants.
Finally, print out which letter was found the most times. (Note there may be more than one letter which has the maximum count attached to it.) Also, print out which letter (or letters) was found the least number of times, but make certain to exclude letters which were not found at all.
This is the small amount of code I have thus far.
import javax.swing.JOptionPane;
public class asgn6 {
   public static void main( String[] args )
      int character;
       String letter = JOptionPane.showInputDialog("Please enter a letter (Type ! when finished) ");
       character = Integer.parseInt (letter);
     if(letter.equals("!"))
     System.exit(0);
}

derajfast wrote:
char letter;
do {
String input = JOptionPane.showInputDialog("Please enter a letter (Type ! when finished) ");
letter= input.charAt(0);
}while (letter != '!');So I figured out the loop!Exellent, that's exactly right.
Now I need a lot of assistance for the arrays part, as that is what I understand least with this assignment.The easiest way I see it is to make an array of ints 128 elements long. Each element is the counter for the character that indexes it.
For instance, 'A' is ASCII 65. So array[65] is the counter for how many times 'A' has been seen. You can use chars like you would use ints, so you can do this: array['A'] and it will convert it to it's ASCII value. Each time you read an input char, increment array[letter].
Then when you're done with input, you can print out each one like this
for each element i in the array
   print out (char)i followed by array                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Windows Vista + nVidia i680 MB + RAID5 + iTunes 7.3.2 = RAID array trouble

    Dunno if any of you can help out with this but I'm at witt's end over this issue.
    I have a Windows Vista box running an Abit In9-32MAX motherboard (nVidia i680 chipset), four drives in a RAID 5 array and using iTunes 7.3.2
    Drivers for the motherboard are the most recent ones from the nVidia site. BIOS for motherboard is also current.
    Practically ANY time I import any audio or video file over 50 MB into iTunes the entire RAID array will degrade. I'm also having issues transcoding video into Quicktime using Videora which seems to be related to this issue. The video simply refuses to play.
    For what it's worth the video/audio content is legit. I own the DVD's that I'm transcoding so I can watch them when I travel.
    Any thoughts, ideas, suggestions, etc appreciated. I'd love to go a whole week without iTunes/Quicktime forcing me to rebuild the RAID array.

    Well, whatever Itunes/quicktime does, it's definitely causing some sort of RAID compatibility. I've had this problem since I got my new rig a month ago. Nvidia 680i SLI board with a RAID 1, and I have it working fine (I've done 3 system restores now) and then I install itunes, and kablooie, there goes the RAID. I can also tell you that even if you disable the mediashield program (NVRAID.exe), it will still happen (this was my last experiment in trying to make it work) and the raid will show up degraded in the BIOS.
    Basically, Apple and Nvidia need to exchange a freaking phone call and try and figure out what is causing it to go bad. from reading around, it's not just apple (though they are the biggest culprit). I've seen people mention bittorrent and some other program whose name escapes me at the moment cause this as well (digital imaging program I think).

  • Having trouble printing an array of prime numbers that has been resized

    HI, im having trouble with my printPrimeNumbers() method printing the current state of an array, I can only get it to print the original state it was in. The array is inside of a primeNumbers object. I used checkAndResize to resize that array. my printPrimeNumbers method must be void without a parameter. How could i get my PrintPrimeNumbers method to print out a resized array without modifying the parameter? Any ideas.
    Here is my PrimeNumbers class:
    * Created by IntelliJ IDEA.
    * User: Kevin
    * Date: Mar 4, 2007
    * Time: 1:53:56 AM
    * To change this template use File | Settings | File Templates.
    package primes;
    public class PrimeNumbers {
        private boolean [] sieve;
        public PrimeNumbers(int  upper) {
            initializeSieve(upper);
        public int getNthPrime (int n){
        int prime = 0;
        double num;
        if (n >= sieve.length)
            checkAndResize(n + 1);
        for (int i = 0; i < sieve.length; i++){
            if(sieve)
    prime++;
    if (prime == n)
    return i;
    if (prime < n && i == sieve.length -1)
    checkAndResize(2*sieve.length);
    return -1;
    public int getNumberPrimeNumbers(int n){
    int primes = 0;
    for (int i =0 ; i < sieve.length ; i ++){
    if (n > sieve.length){
    checkAndResize(n);
    if(sieve[i])
    primes++;
    else if (sieve[i])
    primes++;
    return primes;
    public int getSieveSize ()
    return sieve.length;
    public boolean isPrime (int n) {
    if (n > sieve.length){
    checkAndResize(n);
    //initializeSieve(n);
    return sieve[n];
    // prints out the prime numbers inside sieve
    public void printPrimeNumbers() {
    int n = 0;
    boolean first = true;
    System.out.print("[");
    for(int i = 0; i < sieve.length - 1; i++){
    n++;
    if(sieve[i] == true && n != sieve.length - 1) {
    if(first) first = false;
    else System.out.print(" ");
    System.out.print(i);
    System.out.println("]");
    // checks length of sieve with N and then resizes sieve if nessecary.
    private void checkAndResize (int n){
    if ((n + 1) >= sieve.length){
    initializeSieve(2*n);
    private void setMultiples (int k) {
    for (int i = 2*k; i < sieve.length; i += k)
    sieve [i] = false;
    private void initializeSieve (int upper){
    if ( upper < 2)
    sieve = new boolean [2];
    else
    sieve = new boolean [upper + 1];
    sieve[0] = false;
    sieve[1] = false;
    for (int i =2 ; i< sieve.length; i ++ )
    sieve[i] = true;
    int bound = (int) Math.ceil(Math.sqrt(sieve.length));
    for (int i = 2 ; i < bound ; i ++)
    if (sieve[i])
    setMultiples (i);
    private String booleanToString (boolean value)
    if (value)
    return "T";
    else
    return "F";
    public String toString (){
    StringBuffer buf = new StringBuffer("[");
    for (int i = 0; i < sieve.length -1 ; i ++)
    buf.append(booleanToString (sieve[i]) + " " );
    buf.append(booleanToString (sieve[sieve.length -1]) + "]");
    return buf.toString();
    here is the client code
            PrimeNumbers test = new PrimeNumbers(16);
            System.out.println(test);
            System.out.println("There are " + test.getNumberPrimeNumbers(16) +
                    " prime nummbers in the sieve from 1 to 15. \n");
            System.out.println("There are " + test.getNumberPrimeNumbers(26) +
                    "  prime numbers in the resized sieve from 1 to 25.");
            System.out.println("\nThe first 25 prime numbers are:");// makes sense why it doesnt work
            test.printPrimeNumbers();
            System.out.println("\nThe 13th prime number is: " + test.getNthPrime(13));
            System.out.println();
            System.out.println("The number 3001 is prime:  " + test.isPrime(3001));do you see how my methods resized it?
    here is the output:
    [F F T T F T F T F F F T F T F F F]
    There are 6 prime nummbers in the sieve from 1 to 15.
    There are 15 prime numbers in the resized sieve from 1 to 25.
    The first 25 prime numbers are:
    [2 3 5 7 11 13 17 19 23 29 31 37 41 43 47]// this is only the first 15 elements
    The 13th prime number is: 41
    The number 3001 is prime: true
    thanks for taking your time to look at this

    What's the problem?
    You say that there are 15 prime numbers in the range 1-25. Your method printPrimeNumbers() prints the last calculated primes, and that is 15. So the program works.

  • MSI X58 Pro - I'm having trouble setting up my first Raid 0 Array

    Hey guys!  I have an i7 920, X58 Pro, 3x2GB DDR3, Radeon 5850, 640GB WD Black (Windows 7 64 bit + applications) and 1TB Samsung F3 (backup) system and I'm having trouble setting up a raid 0 array.  I recently decided to purchase two additional 1TB Samsung F3 harddrives in order to create a raid 0 array, while still keeping my original two harddrives separate.  I installed the new harddrives today, installed the JMicron drivers that were on the drivers disk that came with my motherboard, went into the bios, and changed it from IDE to RAID.  I then went into the raid bios, selected the two new harddrives and selected raid 0, saved everything and tried to load Windows and Windows refuses to boot up.  I got an option to try fixing Windows but that didn't end up fixing anything.  Finally, I was forced to go back into the bios and switch it from RAID back to IDE just to get Windows to boot up again.  Does anyone know what I need to do in order to get this raid 0 to work?  Thanks a lot in advance for your help!

    Perhaps create a software RAID? You can do it in Windows through Control Panel --> Administrative Tools --> Computer Management --> Disk Management.
    A quick guide: http://www.softwaresecretweapons.com/jspwiki/windows-7-software-raid-disk-partition-and-volume-context-menus

  • Trouble writing pixel array back to gif file

    Hi everyone. I am in the middle of constructing a steganography api for a final year group project. I have taken out the pixels into an array from a gif file. I am having trouble writing it back to a gif file. Here is my code:
    import javaSteg.stegoLibrary.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.io.*;
    import Acme.*;
    import Acme.JPM.Encoders.*;
    public class Gif extends Canvas{
         public void encodeGif(byte[] imageData){
              //create toolkit obarrayPointerect
              Toolkit t = Toolkit.getDefaultToolkit();
              MediaTracker tracker = new MediaTracker(this);
              //decode specified Gif cover
              Image img = t.createImage(imageData);      
              tracker.addImage(img,0);
              try{
                   tracker.waitForAll();
              catch(InterruptedException e){
              System.out.println("Tracker interrupted.");
              //retrive picture from image
              int[] pix = new int[img.getWidth(this) * img.getHeight(this)];
              PixelGrabber pg = new PixelGrabber(img, 0, 0, img.getWidth(this), img.getHeight(this), pix, 0, img.getWidth(this));
              try{ pg.grabPixels();
              } catch (InterruptedException ioe) {
                   System.err.println("Interrupted");
              if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
              System.err.println("image fetch aborted or errored");
              return;
              //put into byte array
              byte[] pixels = new byte[img.getWidth(this) * img.getHeight(this)];     
              for(int arrayPointer=0;arrayPointer<pix.length;arrayPointer++){
                   pixels[arrayPointer] = new Integer(pix[arrayPointer]).byteValue();
              //edit pixels not implemented yet
    //assign edited pixels to an image
              img = t.createImage(pixels);
              // Now encode the image using ACME free GIF encoder (www.acme.com)
              try{
                   FileOutputStream fos = new FileOutputStream("D:\\result.gif");
                   GifEncoder encoder = new GifEncoder(img, fos);
                   encoder.encode();
                   fos.close();
              }catch(IOException e) {
              System.out.println("FATAL IOException "+e);
    From this i get a single pixel in my output gif file. Is there a way of swapping out the edited pixels with the origonal pixels in the image file? or an alternative way to write back the complete file.
    Thanks a lot
    MickyT

    ive managed to solve it. For those who come across this thread and want to know the solution i needed to use MemoryImageSource with the pixels inorder to pass them to the createImage method :o)

  • [JS CS3] Trouble with changeGrep() array

    This is strange, or else I'm totally missing something simple:
    My script does a GREP search for a text string in a table, and assigns a paragraph style to the string. Next, for each string that was found, I want to merge the cell that contains the string with the two cells directly to the right of the cell. The line
    var myFound = mySelection.changeGrep();
    does the changing of the text string.
    I understand that changeGrep() returns an array, in this case, of insertion points. When I run the script on a table that contains 5 instances of the string that the Grep search is looking for, myFound returns an array of 5 insertion points like I'd expect. Except that if I pause the script and examine the contents of the array, this is what I get:
    myFound[0].parent.contents displays the correct (first) text string that was changed
    myFound[1].parent.contents isn't correct. It displays the contents of the cell directly to the left of he text string that was changed.
    myFound[2] through myFound[4] are also incorrect.
    Again, this is examining the array before I do anything to the table such as merging cells, etc.
    So, why doesn't the array return the correct insertion points?
    Here is the full script function:
    function myProcessTable(mySelection) {
    // Specify the column width
    mySelection.columns.item(0).width = 68;
    mySelection.columns.item(1).width = 103.5;
    mySelection.columns.item(2).width = 24;
    mySelection.columns.item(3).width = 16;
    mySelection.columns.item(4).width = 16;
    mySelection.columns.item(5).width = 16;
    // Find every occurance of ddd.dd/d in the current table, and apply the Table body, cond, center paragraph style,
    app.findGrepPreferences = NothingEnum.nothing;
    app.changeGrepPreferences = NothingEnum.nothing;
    app.findGrepPreferences.findWhat = "\\d.\\d\\d/\\d";
    app.changeGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByID(locateParagraphStyle("Table body, cond, center"));
    var myFound = mySelection.changeGrep();
    alert ("Search is completed. " + myFound.length + " replacement(s) made.")
    // merge the cell with the two cells to the right
    for (i=myFound.length-1; i>=0; i--) { // iterate through each found occurance
    var myCell = myFound[i].parent;
    var myTable = myCell.parent;
    var myRow = myCell.parentRow.index;
    var myColumn = myCell.parentColumn.index;
    myCell.merge(myTable.rows[myRow].cells[myColumn+2]);

    Keith,
    changeGrep()'s arrays can't be used for anything, so that's where your script runs into trouble -- it's nothing to do with tables. To work around that, use findGrep()'s array.Immediately before this line:
    for (i=myFound.length-1; i>=0; i--) { // iterate through each found occurance
    add this one:
    var myFound = mySelection.findGrep();
    Peter

  • Trouble with primitive arrays and casting, lesson 521

    hi everyone!
    there is a problem i discovered right now - after years with java where was no necessity to do this.....
    and i'm shure this must have been the topic already, but i couldn't find any helpful resource :-/
    right here we go:
    1. an array is a (special) kind of object.
    2. there are "primitive" arrays and such containing references to objects. of course - and i imagine why - they are treated differently by the VM.
    3. then both are - somehow - subclasses of Object. whereas primitive types are not really, primitive-arrays are. this is hidden to the programmer....
    4. any array can be "pointed" at via local Object variable, like this:
    Object xyz = new int[6];
    5. arrays of Objects (with different dimensions) can be casted, like this:
      Object pointer = null;
      Object[]   o  = new SomeClass[42] ;
      Object[][] oo = new OtherClass[23] [2] ;
      Object[][][] ooo = new OtherClass[23] [2] [9] ;
      o = oo = ooo;     // this is save to do,
                                   //because "n-dimensional" object-arrays
                                  // are just arrays of  other arrays, down to simple array
    pointer = o;         // ok, we are referencing o via Object "pointer"6. but, you cannot do this with primitive types:
      int[]  i1 = new int [99] ;
      int[][] i2 = new int [1] [3] ;
      i1 = i2                  // terror: impossible. this is awful, if you ask me.
                                   // ok, one could talk about "special cases" and
                                   // "the way the VM works", but this is not of interest to me as
                                   // a programmer. i'm not happy with that array-mess!
      pointer = i2;       // now this is completely legal. i2, i1 etc is an object!7. after the preparation, let's get into my main trouble (you have the answer, i know!) :
    suppose i have a class, with methods that should process ANY kind of object given. and - i don't know which. i only get it at runtime from an unknown source.
    let's say: public void BlackBox( Object x );
    inside, i know that there might be regular objects or arrays, and for this case i have some special hidden method, just for arrays... now try to find it out:
    public void BlackBox( Object x )
      if ( x == null)
           return;
       Class c = x.getClass();
       if ( c.isArray() )
              // call the array method if it's an array.........
              BlackBoxes(     (Object [] )  x );         // wait: this is a cast! and it WILL throw an exception, eventually!
              return;
       else
               DoSpecialStuffWith( x );
    }ok ? now, to process any kind of array, the special method you cannot reach from outside:
    private void BlackBoxes( Object[] xs )
       if ( xs != null )
            for ( Object x : xs )
                 BlackBox( x );
    // this will end up in some kind of recursion with more than one array-dimension, or when an Object[] has any other array as element!this approach is perfectly save when processing any (real) Object, array or "multi-dimensional" arrays of Objects.
    but, you cannot use this with primitive type arrays.
    using generics wouldn't help, because internally it is all downcasted to Object.
    BlackBox( new Integer(3) ) ---- does work, using a wrapper class
    BlackBox( new Integer[3] ) ----- yep!
    BlackBox( 3 ) ---- even this!
    BlackBox( new int[42] ) ---- bang! ClassCastException, Object[] != int[]
    i'm stuck. i see no way to do this smoothly. i could write thousands of methods for each primitive array - BlackBox( int[] is ) etc. - but this wouldn't help. because i can't cast an int[][] to int[], i would also have to write countless methods for each dimension. and guess, how much there are?
    suppose, i ultimately wrote thousands of possible primitive-type methods. it would be easy to undergo any of it, writing this:
    BlackBox( (Object) new int[9] [9] );
    the method-signature would again only fit to my first method, so the whole work is useless. i CAN cast an int[] to Object, but there seems no convenient way to get the real array out of Object - in a generic way.
    i wonder, how do you write a serialisation-engine? and NO, i can't rely on "right usage" of my classes, i must assume the worst case...
    any help appreciated!

    thanks, brigand!
    your code looks weird to me g and i think there's at least one false assumption: .length of a multidimensional array returns only the number of "top-level" subarrays. that means, every length of every subarray may vary. ;)
    well i guess i figured it out, in some way:
    an int is no Object;
    int[ ] is an Object
    the ComponentType of int [ ] is int
    so, the ComponentType of an Object int[ ] is no Object, thus it cannot be casted to Object.
    but the ComponentType of int [ ] [ ] IS Object, because it is int [ ] !
    so every method which expects Object[], will work fine with int[ ] [ ] !!
    now, you only need special treatment for 1-dimensional primitive arrays:
    i wrote some code, which prints me everything of everything:
        //this method generates tabs for indentation
        static String Pre( int depth)
             StringBuilder pre = new StringBuilder();
             for ( int i = 0; i < depth; i++)
                  pre.append( "\t" );
             return pre.toString();
        //top-level acces for any Object
        static void Print( Object t)
             Print ( t, 0);
        //the same, but with indentation depth
        static void Print( Object t, int depth)
            if ( t != null )
                 //be shure it is treated exactly as the class it represents, not any downcast
                 t = t.getClass().cast( t );
                if ( t.getClass().isArray() )
                     //special treatment for int[]
                     if ( t instanceof int[])
                          Print( (int[]) t, depth);
                     // everything else can be Object[] !
                     else
                          Print( (Object[]) t, depth );
                     return;
                else
                    System.out.println( Pre(depth) + " [ single object:] " + t.toString() );
            else
                System.out.println( Pre(depth) + "[null!]");
        // now top-level print for any array of Objects
        static void Print( Object [] o)
             Print( o, 0 );
        // the same with indentation
        static void Print( Object [] o, int depth)
            System.out.println( Pre(depth) + "array object " + o.toString() );
            for ( Object so : o )
                    Print( so, depth + 1 );
        //the last 2 methods are only for int[] !
        static void Print( int[] is)
             Print( is, 0 );
        static void Print( int[] is, int depth)
            System.out.println( Pre(depth) + "primitive array object " + is.toString() );
            // use the same one-Object method as every other Object!
            for ( int i : is)
                 Print ( i, depth + 1 );
            System.out.println( "-----------------------------" );
        }now, calling it with
    Print ( (int) 4 );
    Print ( new int[] {1,2,3} );
    Print( new int[][] {{1,2,3}, {4,5,6}} );
    Print( new int[][][] {{{1,2,3}, {4,5,6}} , {{7,8,9}, {10,11,12}}, {{13,14,15}, {16,17,18}} } );
    Print( (Object) (new int[][][][] {{{{99}}}} ) );
    produces this fine array-tree:
    [ single object:] 4
    primitive array object [I@9cab16
          [ single object:] 1
          [ single object:] 2
          [ single object:] 3
    array object [[I@1a46e30
         primitive array object [I@3e25a5
               [ single object:] 1
               [ single object:] 2
               [ single object:] 3
         primitive array object [I@19821f
               [ single object:] 4
               [ single object:] 5
               [ single object:] 6
    array object [[[I@addbf1
         array object [[I@42e816
              primitive array object [I@9304b1
                    [ single object:] 1
                    [ single object:] 2
                    [ single object:] 3
              primitive array object [I@190d11
                    [ single object:] 4
                    [ single object:] 5
                    [ single object:] 6
         array object [[I@a90653
              primitive array object [I@de6ced
                    [ single object:] 7
                    [ single object:] 8
                    [ single object:] 9
              primitive array object [I@c17164
                    [ single object:] 10
                    [ single object:] 11
                    [ single object:] 12
         array object [[I@1fb8ee3
              primitive array object [I@61de33
                    [ single object:] 13
                    [ single object:] 14
                    [ single object:] 15
              primitive array object [I@14318bb
                    [ single object:] 16
                    [ single object:] 17
                    [ single object:] 18
    array object [[[[I@ca0b6
         array object [[[I@10b30a7
              array object [[I@1a758cb
                   primitive array object [I@1b67f74
                         [ single object:] 99
    -----------------------------and i'll have to write 8 methods or so for every primitive[ ] type !
    sounds like a manageable effort... ;-)

  • Trouble while passing an array as a parameter to an JDBC Control

    Hi everyone, recently I have upgraded my WLS Workshop 8.1 application to WLS 10gR3 using the workshop 8.1 application upgrade but after the upgrade to beehive controls I'm having troubles in a couple of methods that receive an array as a parameter. One of the methods is the following:
    * @jc:sql array-max-length="all" max-rows="all"
    * statement::
    * select COUNT(*) FROM (
    * SELECT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND la.lea_gkey = le.gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: whereClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * employees asign,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = sa.eme_gkey
    * AND asign.gkey = la.eme_gkey
    * AND asign.active='X'
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: assigneeClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: sharedClause})::
    @JdbcControl.SQL(arrayMaxLength = 0,
    maxRows = JdbcControl.MAXROWS_ALL,
    statement = "select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.lea_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: whereClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asign.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: assigneeClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: sharedClause})")
    public Long getProspectsCount(String[] emeGkeyArray, String whereClause, String assigneeClause, String sharedClause) throws SQLException;
    The execution of the method is the following:
    pendingApprovals = leadsListingDB.getProspectsCount(employeeHierarchyArray, pendingApprovalsClause, pendingApprovalsClause, pendingApprovalsClause);
    When the method is executed all the String parameters (whereClause, assigneeClause & sharedClause) are replaced well except the array parameter (emeGkeyArray) so the execution throws the following exception because the array is not replaced:
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: onAquire()>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: invoke()>
    <Jan 20, 2010 1:01:26 PM CST> <Info> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <PreparedStatement: select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, n
    me, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead
    tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.l
    a_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WE
    KLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey I
    ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lea
    tags WHERE tag = 'TARGET') targets,  (SELECT leagkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asi
    n.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey
    = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT
    la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from c
    ntacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags
    WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+
    AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005)) Params:
    {}>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.netui.pageflow.FlowController> <BEA-000000> <Invoking exception handler method handleException(java.lang.Exception, ...)>
    [LeadsMailer] Unhandled exception caught in Global.app:
    java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So the big question is if that behavior is due to a bug of I'm doing something wrong. Do someone can give me an advice about this problem because the array parameter has no problems in workshop 8.1?
    Thanks in advance!

    Greetings
    I may not have an answer for you, but i am in the same boat! I am trying to pass an array to store in the database. I have 2 out of 8 columns that need to be stored as arrays. Everything saves EXEPT for the 2 arrays in question. I am using BEEHIVE with my web app. The strange thing is that i do not receive any syntax errors or runtime codes. I am still searching for an answer. If i find anything out, i will let you know.
    John Miller
    [email protected]

  • Trouble creating and populating an array of objects.

    I'm trying to create/populate an array of objects with consisting of a {string, double, integer}, and am having trouble getting this theory to work in Java. Any assistance provided would be greatly appreciated. Following are the two small progs:
    public class HairSalon
    { private String svcDesc; private double price; private int minutes;
    //Create a constructor to initialize data members
    HairSalon( )
    svcDesc = " "; price = 0.00; minutes = 0;
    //Create a constructor to receive data
         HairSalon(String s, double p, int m)
         svcDesc = s; price = p; minutes = m;
    //Create methods to get the data members
    public String getSvcDesc( )
         return svcDesc;
    public double getPrice( )
         return price;
    public int getMinutes( )
         return minutes;
    public class SortSalon
         public static void main(String[ ] args)
         SortSalon [] sal = new SortSalon[6];
    //Construct 6 SortSalon objects
              for (int i = 0; i < sal.length; i++)
              sal[i] = new SortSalon();
    //Add data to the 6 SortSalon objects
         sal[0] = new SortSalon("Cut"; 10.00, 10);
         sal[1] = new SortSalon("Shampoo", 5.00, 5);           sal[2] = new SortSalon("Sytle", 20.00, 20);
         sal[3] = new SortSalon("Manicure", 15.00, 15);
         sal[4] = new SortSalon("Works", 30.00, 30);
         sal[5] = new SortSalon("Blow Dry", 3.00, 3);
    //Display data for the 6 SortSalon Objects
         for (int i = 0; i < 6 ; i++ )
         { System.out.println(sal[i].getSvcDesc( ) + " " + sal.getPrice( ) + " " + sal[i].getMinutes( ));
         System.out.println("End of Report");

    Hey JavaMan5,
    That did do the trick! Thanks for the assistance. I was able to compile and run the program after adding my sorting routine. Do you happen to see anything I can do to clean it up further, or does it look ok? Thanks again,
    Ironjay69
    public class SortSalon
         public static void main(String[ ] args) throws Exception
         HairSalon [] sal = new HairSalon[6];      
         char selection;
    //Add data to the 6 HairSalon objects
         sal[0] = new HairSalon("Cut", 10.00, 10);
         sal[1] = new HairSalon("Shampoo", 5.00, 11);      
         sal[2] = new HairSalon("Sytle", 20.00, 20);
         sal[3] = new HairSalon("Manicure", 15.00, 25);
         sal[4] = new HairSalon("Works", 30.00, 30);
         sal[5] = new HairSalon("Blow Dry", 3.00, 3);
    System.out.println("How would you like to sort the list?");
         System.out.println("A by Price,");
         System.out.println("B by Time,");
         System.out.println("C by Description.");
         System.out.println("Please enter a code A, B or C, and then hit <enter>");
              selection = (char)System.in.read();
    //Bubble Sort the Array by user selection
              switch(selection)
              case 'A':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'a':
              BubbleSortPrice(sal, sal.length);
                   break;
                   case 'B':
              BubbleSortTime(sal, sal.length);                    break;
                   case 'b':
              BubbleSortTime(sal, sal.length);
                   break;
                   case 'C':
              BubbleSortService(sal, sal.length);
                   break;
                   case 'c':
              BubbleSortService(sal, sal.length);
                   break;
                   default:
              System.out.println("Invalid Selection, Randomly Sorted List!");
    //Display data for the 6 HairSalon Objects
              for (int i = 0; i < sal.length ; i++ )
         System.out.println(sal.getSvcDesc( ) + " " + sal[i].getPrice( ) + " " + sal[i].getMinutes( ));
              System.out.println("___________");
              System.out.println("End of Report");
    public static void BubbleSortPrice(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by price
    int a, b;
    HairSalon temp;
    int highSubscript = len - 1;
    for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array.getPrice() > array[b + 1].getPrice())
              temp = array[b];
              array[b] = array [b + 1];
              array[b + 1] = temp;
    public static void BubbleSortTime(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
              for(b= 0; b < highSubscript; ++b)
         if(array[b].getMinutes() > array[b + 1].getMinutes())
         temp = array[b];
         array[b] = array [b + 1];
         array[b + 1] = temp;
    public static void BubbleSortService(HairSalon[] array, int len)
    // Sorts the items in an array into ascending order by time
         int a, b;
         HairSalon temp;
         int highSubscript = len - 1;
         for(a = 0; a < highSubscript; ++a)
         for(b= 0; b < highSubscript; ++b)
         if(array[b].getSvcDesc().compareTo( array[b + 1].getSvcDesc()) > 0)
                   temp = array[b];
                   array[b] = array [b + 1];
                   array[b + 1] = temp;

  • Trouble with array to spreadsheet string

    I am having trouble with the array to spreadsheet string.
    I have a 1-d array of string, the output spreadsheet string never puts a space on the first row, but all others.
    example:
    05:59:29.170    00000101     8        00 00 07 00 0B 0E 0D 0C
     05:59:29.198    00000100     8        00 00 3A 3A 39 39 39 39
     05:59:29.220    00000101     8        00 00 07 00 0B 0E 0D 0C
     05:59:29.248    00000100     8        00 00 39 39 39 39 39 39
    format string is %s and default tab is delimiter.
    this is screwing up my program because of the "scan for string" function can't be used correctly if the spreadsheet string isnt consistent.
    Any suggestions?
    Thanks

    You don't need to use "array to spreadheet string": You could use plain formatting for full control over the output.
    Still, your observation is a bit odd. Could you attach a simple VI that shows the behavior? (Put your input array into a diagram constant).
    LabVIEW Champion . Do more with less code and in less time .

  • Having trouble with array formula in Numbers

    I should start right away by stating that I am very new to using numbers and array formulas, so potentially I am missing something very basic.
    But, I am having trouble creating a progessive array formula that will allow me to charge users of a system different rates depending on their volume of money going through the system. For instance for their first 10,000 it will be chanrged at 2%, but between 10,000 and 150,000 it will be 1.5%, etc.
    The formula I am using now is =SUM(IF(IF,B15>=B8:B11,B8:B11-B7:B10,B15-B7:B10+.001)>0,IF(B15>=B8:B11,B8:B11-B 7:B10,B15-B7:B10+.001),0)*D7:D10).
    Where B15 is the total money; B7:B10 are the values where a new percentage rate starts, and B11 is just a maximum value; and D7:D10 is the list of corresponding percentages.
    Thanks in advance!
    Kyla

    HI Kyla,
    Following up on Jerry's suggestion, here's an example that may do what you're looking for.
    Main is a table containing several examples of possible amounts and the related charges. Note that for ease of seeing the results of calculations, each amount is either at or 100 above a threshold value at which rates change.
    The Rates table lists the threshold values in column A, the rate charged for amounts from that value to the next threshold value in column B, and the total amount charged for amounts up to the that threshold in column C.
    For example, an amount of one million one hundred (in whatever currency unit is being used) would be charged 11,675 on the first one million, and 0.75 on the one hundred exceeding that threshold, for the total shown in Main::C10.
    Formulas:
    Rates::C2:  (entered value) 0
    Rates::C3, and filled down: =C2+(A3-A2)*B2
    Main::C2, and filled down: =LOOKUP(B2,Rates :: A,Rates :: C)+(B2-LOOKUP(B2,Rates :: A,Rates :: A))*LOOKUP(B2,Rates :: A,Rates :: B)
    Each of the three LOOKUP functions will find the largest amount in Rates, column A that is less than or equal to the amount in B2 (of Main, the table containing the formula), and return the amount from the same row of Rates and the specified column.
    The first LOOKUP returns the amount due on the part of of the amount in Main::B2 up to the highest threshold amount reached, the second returns that threshold amount, which is subtracted from the amount in Main::B2 to determine the 'marginal amount', which is then multiplied by the rate, returned by the third LOOKUP function. That result is added to the amount returned by the first LOOKUP, and the result placed in Man::C2.
    Regards,
    Barry

  • Having trouble converting array to spreadsheet string, storing the file and coverting back to array with complex numbers

    I am working with a network analyzer. I have arrays made of 5 columns the first consisting of an integer and the next four consisting of complex numbers. I am converting the array into a spreadsheet string and then saving the file using the write characters to a file VI. That seems to work well as when I open the file in Excel all the data is there. However when I try to reverse the process, open file and convert back to array, I loose some of the data. Specifically the imaginary parts of my complex numbers are all going to zero. I have narrowed down the problem to be in the conversion from spreadsheet string to array and vice versa. I
    think the problem may be with the 'format' input to the VI. I do not have an adequate resource for this so I am not sure what to put in to accomplish my task. Any takers?

    Hi Biz
    I don't think there is a direct way of converting a complex number to a
    string, so when you convert the array to a spreadsheet string, the
    numbers would be converted to real data.
    However, you could try separating the real and imaginary parts using the
    "Numeric: Complex to Re/Im" function, and then store these - either in
    separate files or in adjacent columns/rows in the same file. Then, when
    you read in the data again, use the "Numeric: Re/Im to Complex" function
    to put the two "halves" together.
    If you actually want Excel to interpret the numbers as imaginary, then
    you'll probably want to create a string for each complex number of the
    form "Re + Im*i" (after separating the Re and Im parts), by using
    "String:Format into String" with 2 numeric inputs and the format string
    "%f+%fi".
    Reading the data back into Labview then would require splitting the
    string into the 2 pieces by using "Stringcan from String" with 2
    numeric outputs (smae precision as original numbers specified by the 2
    Default Value inputs) and the same format string "%f+%fi", and then using
    the above-mentioned "Numeric: Re/Im to Complex" function. It worked for
    me, so if you can't follow what I am describing, send me an email and I
    can email you what I did (LV 5.1.1).
    Paul
    Biz wrote:
    > Having trouble converting array to spreadsheet string, storing the
    > file and coverting back to array with complex numbers
    >
    > I am working with a network analyzer. I have arrays made of 5 columns
    > the first consisting of an integer and the next four consisting of
    > complex numbers. I am converting the array into a spreadsheet string
    > and then saving the file using the write characters to a file VI. That
    > seems to work well as when I open the file in Excel all the data is
    > there. However when I try to reverse the process, open file and
    > convert back to array, I loose some of the data. Specifically the
    > imaginary parts of my complex numbers are all going to zero. I have
    > narrowed down the problem to be in the conversion from spreadsheet
    > string to array and vice versa. I think the problem may be with the
    > 'format' input to the VI. I do not have an adequate resource for this
    > so I am not sure what to put in to accomplish my task. Any takers?
    Research Assistant
    School of Physiotherapy, Curtin University of Technology
    Selby Street, Shenton Park, Western Australia, Australia. 6008
    email: [email protected]
    Tel. +61 8 9266 4657 Fax. +61 8 9266 3699
    "Everyone who calls on the name of the Lord will be saved." Romans 10:12
    "For all have sinned and fall short of the glory of God, and are
    justified freely by his grace through the redemption that came by Christ
    Jesus." Romans 3:23-4

  • Trouble with sending huge arrays via DataSocket​s.

    Hi,
    I am having trouble sending huge arrays via Data Sockets from my main vi on the server PC to the vi on the client PC.
    To further elaborate, in my main vi program I have created 3 arrays called Array1, Array2 and Array3 on my front Panel. By right clicking the mouse on each set of array and from the pop-up menu I selected Data Operations-> DataSocket Connection and I entered dstp://localhost/Array1 and clicked on Publish to broadcast the data from Array1. Similarly, I did the same for Array2 and Array3.
    Now, in my client vi program I have created three arrays on my front Panel to read (Subscribe) the data from the three arrays broadcasted via DataSockets from the server’s main vi program. To subsc
    ribe the data I did the similar process above and clicked on Subscribe to read the data (of course the IP address of the client PC will be different then the server PC so enter the hosts IP address). Once the data is received in the client arrays, I am using LV2 globals so that I can use these arrays on other sub-vi’s locally (instead of having each sub-vi get data from the server directly).
    I succeeded in doing this with two arrays, however when I added the third array the DataSockets would not work consistently. For example the refresh rate would get slower at times and sometimes 2 out of the 3 arrays would update. I don’t know if I have exceeded the limit on how much data DataSockets can broadcast, but I need to have some mechanism to broadcast 6 arrays (approx. 10000 elements for each array) of double digits precision.
    Has anyone come across this issue? Is there another way of broadcasting data more efficiently then DataSockets?
    I would appreciate any
    help that I can get.
    I have attached the files for this program in the zip file.
    First run the Server main program, testServeMainVI.vi, and then the client program, testClientMainVI.vi.
    Thanks
    Nish
    Attachments:
    beta2.zip ‏70 KB

    DataSocket can be a lossy communication. I like the advice to flatten the data to a string, but another option would be to buffer the communcation. The problem might be that the data is being overwritten on the server faster than it is being read. There is an example of buffered datasocket on NI web page: http://venus.ni.com/stage/we/niepd_web_display.DIS​PLAY_EPD4?p_guid=BA3F9DFED17F62C3E034080020E74861&​p_node=DZ52000_US&p_submitted=N&p_rank=&p_answer=&​p_source=Internal
    Also, I have played with the new built in buffered datasocket in LabVIEW 7.0. It is pretty slick. If buffers the data both on the server and the client side.

  • Trouble With my array

    Hi everyone
    Im having trouble completing this code... what i want is for every loop through the method the gallows[][] should go down to the next one. You will see what i mean if you read the comments below.
    Thanx heaps for your help guys
    import java.io.*;
    import java.util.*;
    public class Gallows
       public static void main(String[] args)
          char bodyPart;
          char[][] gallows = new char[6][7];
          gallows[0][0] = '-';
          gallows[1][0] = '|';
          gallows[2][0] = '|';
          gallows[3][0] = '|';
          gallows[4][0] = '|';
          gallows[5][0] = '|';
          gallows[0][1] = '-';
          gallows[0][2] = '-';
          gallows[0][3] = '-';
          gallows[0][4] = '-';
          gallows[0][5] = '-';
          gallows[1][5] = '|';
          gallows[2][5] = '0';
          gallows[2][4] = '\';
          gallows[2][6] = '/';
          gallows[3][5] = '|';
          gallows[4][4] = '/';
          gallows[4][6] = '\';
          Display gallows[0][0] to [0][5] so that something like this is displayed:
          |
          |
          |
          |
          |
          if guess does not equal a letter in the word
               print out the next part of the array.
               eg. the first wrong guess will get the gallows[1][5].
               It will then repeat and the next wrong guess will be [2][5]
               etc etc
    }

    disregard that last post..
    The last thing i need to do is make it so that when every part of the array is display (7 wrong guesses) it is to stop the program and display "Bad luck".
    I just dont know where to put this code ... Here are both classes...
    import java.io.*;
    import java.util.*;
    public class Hangman
        static Scanner console = new Scanner(System.in);
        public void play()
            String player;
            System.out.println(" ******WELCOME TO HANGMAN******");
            System.out.println(" ------------------------------");
            System.out.println("       What is your name?       ");
            player = console.nextLine();
            System.out.println("   **Welcome " + player + " & good luck!!**");
            System.out.println("");
            processLetter();
        public void processLetter()
            String input;
            String word;
            int num;
            boolean wordflag;
            Gallows gallows = new Gallows(); // <- added this
            gallows.displayGallows(); // <- and this
            String[] words = new String[10];
            words[0] = "MELBOURNE";
            words[1] = "BEER";
            words[2] = "BRICKLAYER";
            words[3] = "RAINFALL";
            words[4] = "PRISON";
            words[5] = "COLLINGWOOD";
            words[6] = "BOTTLE";
            words[7] = "PUPPY";
            words[8] = "LANGUAGE";
            words[9] = "FISHTANK";
            num = (int)Math.round(Math.random()*9);
            word = words[num];
            StringBuffer wb = new StringBuffer(word);
            for (int i = 0; i < word.length(); i++) wb.setCharAt(i, '-');
            System.out.println("           " + wb);
            System.out.println("Enter a letter or an entire word ");
            boolean letters[] = new boolean['Z' - 'A' + 1];
            for (char i = 'A'; i < 'Z'; ++i)
                letters[i - 'A'] = false;
            input = console.nextLine();
            wordflag = true;
            while (wordflag)
                String newInput = input.toUpperCase();
                if (newInput.equals(word))
                    System.out.println("Congratulations. You have guessed correctly!!!");
                    break;
                char guess = input.charAt(0);
                guess = Character.toUpperCase(guess);
                letters[guess - 'A'] = true;
                for (int i = 0; i < word.length(); i++)
                    int k = word.indexOf(guess, i);
                    if (k >= 0) wb.setCharAt(k, guess);
                if (word.indexOf(guess) == -1) gallows.wrongGuess(); // <- added this line
                gallows.displayGallows(); // <- and this line
                System.out.println("");
                System.out.println("           " + wb);
                System.out.println("");
                System.out.print("Letters Tried: ");
                for (char i = 'A'; i <= 'Z'; ++i)
                    if (letters[i - 'A']) System.out.print(i);
                if (wb.toString().equals(word))
                    System.out.println("");
                    System.out.println("Congratulations, You have guessed the correct word!!!");
                    wordflag = false;
                } else
                    System.out.println("");
                    System.out.println("----------------------------------");
                    System.out.println("Enter a letter or the entire word ");
                    input = console.nextLine();
    }and
    public class HangmanGallows
        public static void main(String[] args)
            Gallows g = new Gallows();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows();
    class Gallows
        private final char[] gallows = new char[]
                {'-', '-', '-', '-', '-', '-', '\n',
                 '|', ' ', ' ', ' ', ' ', '|', '\n',
                 '|', ' ', ' ', ' ', ' ', 'O', '\n',
                 '|', ' ', ' ', ' ', '/', '|', '\\', '\n',
                 '|', ' ', ' ', ' ', '/', ' ', '\\', '\n',
                 '|'};
        private boolean[] display = new boolean[]
                {true, true, true, true, true, true, true,
                 true, true, true, true, true, false, true,
                 true, true, true, true, true, false, true,
                 true, true, true, true, false, false, false, true,
                 true, true, true, true, false, true, false, true,
                 true};
        private final int[] bodyParts = new int[] {12, 19, 25, 26, 27, 33, 35};
        private int wrongGuesses = 0;
        public void displayGallows()
            for (int i = 0; i < gallows.length; i++)
                if (display)
    System.out.print(gallows[i]);
    System.out.println();
    public void wrongGuess()
    if (gameOver()) return;
    display[bodyParts[wrongGuesses]] = true;
    wrongGuesses++;
    public boolean gameOver()
    return wrongGuesses == bodyParts.length;
    thanx heaps for your help guys....

  • Having trouble with my array...

    Hi everyone
    Im having trouble completing this code... what i want is for every loop through the method the gallows[][] should go down to the next one. You will see what i mean if you read the comments below. Also why does this code give me an error of "unclosed Character Literals". Its got something to do with the '/' and '\' in the array.
    Thanx heaps for your help guys
    import java.io.*;
    import java.util.*;
    public class Gallows
       public static void main(String[] args)
          char bodyPart;
          char[][] gallows = new char[6][7];
          gallows[0][0] = '-';
          gallows[1][0] = '|';
          gallows[2][0] = '|';
          gallows[3][0] = '|';
          gallows[4][0] = '|';
          gallows[5][0] = '|';
          gallows[0][1] = '-';
          gallows[0][2] = '-';
          gallows[0][3] = '-';
          gallows[0][4] = '-';
          gallows[0][5] = '-';
          gallows[1][5] = '|';
          gallows[2][5] = '0';
          gallows[2][4] = '\';
          gallows[2][6] = '/';
          gallows[3][5] = '|';
          gallows[4][4] = '/';
          gallows[4][6] = '\';
          Display gallows[0][0] to [0][5] so that something like this is displayed:
          |
          |
          |
          |
          |
          if guess does not equal a letter in the word
               print out the next part of the array.
               eg. the first wrong guess will get the gallows[1][5].
               It will then repeat and the next wrong guess will be [2][5]
               etc etc
    }

    Here's an equally funny way to do this:public class Foo
        public static void main(String[] args) {
            Gallows g = new Gallows();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows(); g.wrongGuess();
            g.displayGallows();
    class Gallows
        private final char[] gallows = new char[]
                {'-', '-', '-', '-', '-', '-', '\n',
                 '|', ' ', ' ', ' ', ' ', '|', '\n',
                 '|', ' ', ' ', ' ', ' ', 'O', '\n',
                 '|', ' ', ' ', ' ', '/', '|', '\\', '\n',
                 '|', ' ', ' ', ' ', '/', ' ', '\\', '\n',
                 '|'};
        private boolean[] display = new boolean[]
                {true, true, true, true, true, true, true,
                 true, true, true, true, true, false, true,
                 true, true, true, true, true, false, true,
                 true, true, true, true, false, false, false, true,
                 true, true, true, true, false, true, false, true,
                 true};
        private final int[] bodyParts = new int[] {12, 19, 25, 26, 27, 33, 35};
        private int wrongGuesses = 0;
        public void displayGallows() {
            for (int i = 0; i < gallows.length; i++) {
                if (display)
    System.out.print(gallows[i]);
    System.out.println();
    public void wrongGuess() {
    if (gameOver()) return;
    display[bodyParts[wrongGuesses]] = true;
    wrongGuesses++;
    public boolean gameOver() {
    return wrongGuesses == bodyParts.length;

Maybe you are looking for

  • Problem with dbms_metadata.get_ddl

    When I issue following statement: Select DBMS_METADATA.GET_DDL ('TABLE', 'ACQ_OPSC') From Dual; I get these errors. Error: ORA-06502: PL/SQL: Numeric or Value Error. LPX-00210: Expected '<' instead of 'n' ORA-06512: at "sys.utl_xml", line 0 bunch mor

  • Why doesn't Photoshop see my scanner or the plugin? (Mac OS)

    Just loaded CS4 on Mac 10.5.7.  I downloaded and installed the  latest OSX Epson 1240U scanner software, and also copied the Twain plugin from the Adobe Goodies CD to the Photoshop > Plugins > Import/Export folder.  Rebooted the computer, power off a

  • BDC ok_code

    Hi,   Please let me know BDC ok_code for scroll down functionality in ME21n. i tried using '=P+' it is not working. Please suggest. Thank you. Regards, venkatesh

  • Forte UDS 5.1.8 Syntax

    I am primarily a C# programmer with some java experience. We have an application that we purchased that uses Forte UDS 5.1.8. The syntax is easy to figure out but there is one thing that I have not been able to find documentation on. It is database o

  • I received an e-mail regarding unusual activity on my account

    I recently received an e-mail from [email protected] regarding my account activity saying that they has been unusual activity and to update my information at a website provided. Is this spam?