36 Replies - 1858 Views - Last Post: 20 July 2009 - 05:12 PM
#1
outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:14 PM
a random number is picked from the String and is stored in the variable named card
i am trying to take the string and replaces the 1 in position card with a 0;
if u need classrification post right away i am online NOW
Replies To: outputing suits like hearts, diamonds, spades
#2
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:22 PM
char [] characters = "Hello".toCharArray();
this will split the string in to an array of {'H', 'e', 'l', 'l', 'o' }.. so now you can choose a random character and then set it to whatever value u want by simply using its index to access it in the array
characters[index] = '0';
hope this helps
#3
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:25 PM
I store the integer value of card divided by 13 in an int named suit
so it will be like this 4/13 = 0 14/13 = 1 34/13 =2
then i write a statement that increases the value stored in suit by 3 and diplays the character value of this int
out.println((char)(suit+3));
this is SUPPOSED by the instructer to output the suit of cards
ty if u can help
ONLINE NOW
#4
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:29 PM
mostyfriedman, on 18 Jul, 2009 - 12:22 PM, said:
char [] characters = "Hello".toCharArray();
this will split the string in to an array of {'H', 'e', 'l', 'l', 'o' }.. so now you can choose a random character and then set it to whatever value u want by simply using its index to access it in the array
characters[index] = '0';
hope this helps
i cant use arrays
#5
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:34 PM
#6
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:40 PM
mostyfriedman, on 18 Jul, 2009 - 12:34 PM, said:
int pos = deck.indexOf(deck.charAt(card)); deck=deck.charAt(pos)="0";
do you mean this
it dont work
#7
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:44 PM
deck[indexSaved] = "0";
#8
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:52 PM
String result = "";
for(int i = 0; i < str.length(); i++)
{
if(randomIndex == i)
result += 0;
else
result += str.charAt(i);
}
str is the original string, and randomIndex is the index of the number from the string that used for a card..it should be clear now
This post has been edited by mostyfriedman: 18 July 2009 - 01:53 PM
#9
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 01:57 PM
mostyfriedman, on 18 Jul, 2009 - 02:52 PM, said:
result += 0;
Use result += "0";
But before, I was under the impression we were using an array...nevermind.
This post has been edited by Locke: 18 July 2009 - 02:06 PM
#10
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 02:04 PM
Locke, on 18 Jul, 2009 - 12:57 PM, said:
we were using an array until he said he cant use one..but btw it wont give an error since i'm concatenating an int with a string, the result will be also a string..it would give an error i was setting the 0 to the string and not to concatenating it..
like
result = 0;
that would give an error, but the other one wouldnt
#11
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 02:06 PM
#12
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 02:09 PM
#13
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 08:12 PM
This post has been edited by hlln: 19 July 2009 - 12:17 AM
#14
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 09:08 PM
#15
Re: outputing suits like hearts, diamonds, spades
Posted 18 July 2009 - 09:44 PM
|
|

New Topic/Question
Reply



MultiQuote





|