what's wrong with this code?
I've been trying the following code for a while but in vain. I've tried simple text editors and even various IDEs. Please tell me what's wrong with this:
import java.util.Random;
class PlayTwentyOne {//even adding "public" before makes no difference
public static void main(String args[]) {
Random myRandom = new Random();
int card, total = 0;
System.out.println(“Card Total”);
while (total < 21) {
card = myRandom.nextInt(10) + 1;
total += card;
System.out.print(card);
System.out.print(“ “);
System.out.println(total);
}
if (total == 21) {
System.out.println(“You win :-)”);
} else {
System.out.println(“You lose :-(“);
}
}
}
Re: what's wrong with this code?
where are you from? Looks right for me, just problems with commas (not sure of name, I mean this -> " ). Try it:
import java.util.Random;
class PlayTwentyOne {//even adding "public" before makes no difference
public static void main(String args[]) {
Random myRandom = new Random();
int card, total = 0;
System.out.println("Card Total");
while (total < 21) {
card = myRandom.nextInt(10) + 1;
total += card;
System.out.print(card);
System.out.print(" ");
System.out.println(total);
}
if (total == 21) {
System.out.println("You win :- ");
} else {
System.out.println("You lose :-(");
}
}
}
Re: what's wrong with this code?
When i tried to run your code in netbeans, the only errors it gave were to do with the quotation marks surrounding your strings. I re-entered the quotation marks again, and your program runs.
Re: what's wrong with this code?
Thats what I said. Code looks right.
Re: what's wrong with this code?
Quote:
Please tell me what's wrong
You first...does it compile? Are there exceptions? Does it behave as expected? You don't want to leave us guessing do you?
Re: what's wrong with this code?
Forum Rules -- particularly the third paragraph
http://www.java-forums.org/forum-gui...w-members.html
BB Code List - Java Programming Forum
Don't be too lazy to type your code. The cause of your problem is copy/paste.
db
Re: what's wrong with this code?
First of all thanks everyone for replying so quickly.
@musclecode: yes, the code looks right and actually it runs now perfectly.
@wdh321: yes, that solves the problem! I guess the error arose due to mismatch in text formats.
@DarrylBurke: Sir, I am not lazy. But yes, after running it in various editors, I resorted to copy paste after a few runs.
By the way, I'd like to know why this happened?
(I mean this shouldn't have been the case with the simple notepad text editor.)
But anyways, I learned a new thing today. So, thank you all very much.