Computer Science Canada stuck on a java question, help please |
Author: | ImDennis [ Fri Nov 04, 2011 3:16 pm ] |
Post subject: | stuck on a java question, help please |
so im doing code labs and i seem to of stumbled apawn a question that i cant seem to figure out, the question is Quote: Write a statement that compares the values of score1 and score2 and takes the following actions. When score1 exceeds score2 , the message "player1 wins" is printed to standard out. When score2 exceeds score1 , the message "player2 wins" is printed to standard out. In each case, the variables player1Wins, , player1Losses , player2Wins, and player2Losses, , are incremented when appropriate. Finally, in the event of a tie, the message "tie" is printed and the variable tieCount is incremented. and my code that i got is Quote: if (score1>score2)
{ System.out.println("player1 wins"); } else if (score1<score2) { System.out.println("player2 wins"); } else if (score1==score2) { System.out.println("tie" + tieCount); } anyone know whats wrong? it seems right to me |
Author: | DemonWasp [ Fri Nov 04, 2011 3:19 pm ] |
Post subject: | RE:stuck on a java question, help please |
and the variable tieCount is incremented. ^ You're missing that part. (I'm assuming, of course, that you have the rest of the program that goes around the snippet you posted -- a main() method, some variable declarations, a class declaration, etc.) |
Author: | ImDennis [ Sat Nov 05, 2011 11:30 am ] |
Post subject: | Re: stuck on a java question, help please |
yea i got it working but now im stuck on another one if you wouldn't mind helping , the question is Quote: yea i got it working but now im stuck on another one if you wouldn't mind helping , the question is and my code is Quote: 1 import java.util.Scanner;
2 3 class CTest { 4 public static void main(String [] args) { 5 Scanner stdin = new Scanner(System.in); 6 7 int modelYear = 0; 8 9 (modelYear >=1995) && (modelYear <=1998) || (modelYear >=2004) && (modelYear 2004) 10 System.out.println("RECALL"); 11 12 13 } 14 } any suggestions? i tried but couldn't seem to of figured it |
Author: | ImDennis [ Sat Nov 05, 2011 11:36 am ] |
Post subject: | Re: stuck on a java question, help please |
ImDennis @ Sat Nov 05, 2011 11:30 am wrote: yea i got it working but now im stuck on another one if you wouldn't mind helping , the question is
Quote: yea i got it working but now im stuck on another one if you wouldn't mind helping , the question is and my code is Quote: 1 import java.util.Scanner;
2 3 class CTest { 4 public static void main(String [] args) { 5 Scanner stdin = new Scanner(System.in); 6 7 int modelYear = 0; 8 9 (modelYear >=1995) && (modelYear <=1998) || (modelYear >=2004) && (modelYear 2004) 10 System.out.println("RECALL"); 11 12 13 } 14 } any suggestions? i tried but couldn't seem to of figured it update i was reading through my java book and i did a few mods to that hting but still nothing, heres what i got Quote: if (modelYear >=1995 && modelYear <=1998) || (modelYear >=2004 && modelYear 2004)
System.out.println("RECALL");("RECALL"); |
Author: | Velocity [ Fri Feb 10, 2012 11:05 am ] |
Post subject: | RE:stuck on a java question, help please |
thats sooo easy, { if p1 >= p2 System.println ("p1 wins') elsif p1 <= p2 System.println ("p2 wins") } in one function. |
Author: | Velocity [ Fri Feb 10, 2012 11:06 am ] |
Post subject: | RE:stuck on a java question, help please |
thats sooo easy, { if p1 >= p2 System.println ("p1 wins') elsif p1 <= p2 System.println ("p2 wins") } in one function. |