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?");
}
}
}
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
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 );
}
}
}
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?");
}
}
}
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