Home > Default > Strings

Strings

November 30Hits:0
Advertisement
I am trying to create a simple program where I have a deck of card of 52...for this program I have simplyfied it to 8
I need to to cut the deck in half and take the bottom card from each half and put them in a new pile.
I want to keep on shuffling that way till I reach the original deck.
Here is my code so far...but I don't know how to compare strings to make a loop stop...
if(theDeck.equals(values)) break; does not work
I am a beginner Java....need help
public class Cards
     public static void main(String[] args)
          char [] theDeck=new char [52];
          char [] theDeck2=new char [52];
          char [] temp=new char [52];
            int w,x,y,z,k,i;
            int count2=0;
          char [] values={'1','2','3','4','5','6','7','8',};
          System.out.println(values);
          temp=values;
          for(;;)
          for( w = x = 0, y = z = values.length/2;  x < z  &&  y < values.length;   x++,y++ )
               theDeck[w++]=temp[x];
                   theDeck[w++]=temp[y];
          System.out.println(theDeck);
          for(i=0;i<theDeck.length;i++)
              if(theDeck.equals(values)) break;
          for( w = x = 0, y = z = values.length/2;  x < z  &&  y < values.length;   x++,y++ )
                         temp[w++]=theDeck[x];
                             temp[w++]=theDeck[y];
          System.out.println(temp);
}

Answers

OK, ALWAYS put {} around anything like loops of if statements.
This will stop any bugs creeeping in, and if you do don't, i guarantee you will get some!
Anyways, to your problem, this is your code:
System.out.println(theDeck);
     for(i=0;i<theDeck.length;i++)
          if(theDeck.equals(values)) break;
Change it to this:
System.out.println(theDeck);
boolean endLoop = false;
for(i=0; i<theDeck.length() && !endLoop; i++) {
if(theDeck.equals(values)) {
endLoop = true;
}

Read other 6 answers

Tags:

Related Articles

  • Cannot assign an empty string to a parameter with JDBC type VARCHAROctober 11

    Hi, I am seeing the aforementioned error in the logs. I am guessing its happening whenever I am starting an agent instance in PCo. Can somebody explain whats going on? Regards, Chanti. Heres the complete detail from logs - Log Record Details    Messa

  • Problems with string comparison and\or If statementOctober 11

    Right now I'm trying to make a program that will look into all of my music folders, and rename the .mp3 files to a format i want, based on the id3 tags. The program so far looks in all of the folders I want it to, but I get stuck when I need to check

  • Oracle, Null and empty StringsOctober 11

    Currently I'm facing problems with a class, which contains a String, which is set to "" (empty String). When the class is persistent, oracle writes null to the table column (which seems to be common oracle behaviour) and when retrieving the clas

  • NULL and Empty StringOctober 11

    Hi There, As far as I know, Null is not the same as an empty string; however, when I try this out, I get some unexpected results (well, at least unexpected for my liking): SQL> CREATE TABLE TS (MID NUMBER,   2  MDESC VARCHAR2(20) DEFAULT '' NOT NULL)

  • Null and empty string not being the same in object?October 11

    Hello, I know that null and empty string are interpreted the same in oracle. However I discovered the strange behaviour concerning user defined objects: create or replace TYPE object AS OBJECT ( value VARCHAR2(2000) declare xml xmltype; obj object; b

  • Difference in Null and Empty StringOctober 11

    Hi, I have been wondering about the difference between Null and Empty String in Java. So I wrote a small program like this: public class CompareEmptyAndNullString {      public static void main(String args[]) {           String sNull = null;         

  • SSRS Report Returning Double Quote string from a Single Quote StringOctober 11

    Hi, I'm getting weird thing in resultset from SSRS report when executed. When I pass parameter to a report, which passes String that has single quote value to a split function , it returns rows with double quote.  For example  following string: 'N ga

  • How can I convert an int to a string?October 11

    Hi How can I convert an int to a string? /ad87geaoHere is some the code: public class GUI     extends Applet {   public GUI() {      lastValue = 5;     String temp = Integer.toString(lastValue);     System.out.println(temp);     showText(temp);   pri

  • No calendar change for a single event in a recurrring string of eventsOctober 11

    Why won't iCal allow me to change the calendar for a single event in a string of recurring events? Why am I not allowed this, but can change other details and even get prompted whether I want these changes to take effect over the single event or all

  • How do i find the length of a string??October 11

    trying to use the substring, I know the beginIndex (in my case 10), but the string will vary in size and so i need to find the last character and set it as the endIndex, how do i do this? public String substring(int beginIndex, int endIndex)Returns a

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 0.681 s.