begginer java programmer

need help with this assignment....
[41 byte] By [johnsomwa] at [2007-11-26 15:24:32]
# 1
?
DrLaszloJamfa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 2
sorry here it is:Write a Java program to read a character typed on the keyboard and if the character is a 憌?write the line, 揋ame Over; You Won!?to the console; if the character is anything else, write the line 揧ou Lose.Play again?i will post what i have so far
johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 3

import java.io.*;

public class Lab1 {

public static void main(String[] args) {

char c;

System.out.println("Welcome to the Win or Lose game!");

System.out.println("Please enter a character:");

if(c == 'w' || c == 'W'){

System.out.println("Game Over; You Won!");

}

else{

System.out.println("You Lose.Play again?");

}

}

}

johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 4
Do you have a *SPECIFIC* question?
DrLaszloJamfa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 5
need the command so i can input a character....also which loop would work best
johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 6

import java.io.*

public static void main(String[] xxx)throws Exception {

BufferedReader teclado = new BufferedReader (new InputStreamReader(System.in));

to read chars , ask the question and under that do:

char c = teclado.readLine().trim().charAt(0);

that's all

Java__Estudantea at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 7

ok this is what i just got...i got it to work when i input a 'w' it prints you win game over and any other character i prints you lose play again? question now is how do i get it to go back and loop to the begginning to start over?

import java.io.*;

public class Lab01 {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("Welcome to the Win or Lose game!");

System.out.println("Please enter a character:");

char c;

try{

do{

c = (char) System.in.read();

if(c == 'w' || c == 'W'){

System.out.println("Game Over; You Won!");

}

else{

System.out.println("You Lose.Play again?");

c = (char) System.in.read();

}

}

while(c == 'y' || c == 'Y');

}

catch (IOException ioe) {

System.out.println( "IO error:" + ioe );

}

}

}

johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 8
oh i just did it a different way....posted what i have
johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 9

its looking better now last question is the loop...not sure how to go about it for it the play again?

import java.io.*;

public class Lab1 {

public static void main(String[] args) throws Exception{

System.out.println("Welcome to the Win or Lose game!");

System.out.println("Please enter a character:");

BufferedReader character = new BufferedReader (new InputStreamReader(System.in));

char c = character.readLine().trim().charAt(0);

if(c == 'w' || c == 'W'){

System.out.println("Game Over; You Won!");

}

else{

System.out.println("You Lose.Play again?");

}

}

}

johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 10
Well, you figured out (supposing you didn't steal the code you already have) how to prompt the user and read his input, so you'd need to do the same kind of thing to ask him for the Y/N answer.
warnerjaa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 11

post your code betweencode tags[ .code][./code]

char answer;

do{

System.out.print("something: ");

char Char = key.readLine().trim().charAt(0);

if(Char == 'w'){

System.out.println("True");

}else System.out.println("False");

System.out.print("Wanna play again?");

answer = key.readLine().trim().charAt(0);

}while(answer == 'y');

btw, try to read the java tutorial , or any java book , it has the basic that u need to know, loops, etc..

Joao

Java__Estudantea at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 12
thanks everyone for your help....sorry im not good and i had dumb questions
johnsomwa at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...
# 13
we have to start from the begining , no problem...but like i said it will be useful for u , if u read any Java Book or tutorial about the loops, variables and arrays.
Java__Estudantea at 2007-7-8 21:40:02 > top of Java-index,Java Essentials,New To Java...