🔒 Closed Tulong po sa java debug

Status
Not open for further replies.

Renzpbg

Leecher
ito po yung code ko pa help po
yung mga naka highlight na word yan po yung problem
Java:
public class exam {
public static String word = null;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("This is a guessing words game.");
System.out.println("Type the word to use or type random to use a random word.");
word = input.nextLine();
if(word.equals("random")) {
switch (rand(11)) {
case 0:
word = "hello";
break;
case 1:
word = "bye";
break;
case 2:
word = "what";
break;
case 3:
word = "cool";
break;
case 4:
word = "hi";
case 5:
word = "sweet";
break;
case 6:
word = "call of duty";
break;
case 7:
word = "funny";
break;
case 8:
word = "woof";
break;
case 9:
word = "computer";
break;
case 10:
word = "laptop";
break;

}
}
wordOne();
}
private static int rand(int bound) {
return (int) (Math.random() * bound);
}
public static void wordOne() {
int tries = 0;
boolean gotIt = false;
String inputWord = null;
Scanner input = new Scanner(System.in);
System.out.println("You will have 50 tries to get this word");
if(tries >= 49) {
System.out.println("You have exided the maximum number of tries.");
gameOver();
}
while (tries <= 50) {
inputWord = null;
System.out.println("Enter a letter you think the word may contain");
System.out.println("If you want to try and guess just type the word.");
System.out.println("");
inputWord = input.nextLine();
tries++;

if(inputWord.equals(word)) {
System.out.println("Youve got it nice one!!");
sleep(1000);
return;
}
if(word.contains(inputWord)) {
System.out.println("You have guessed right, it does contain a "+inputWord);
}
else
{
System.out.println("Sorry you have guessed wrong.");
}
}

}
public static void gameOver() {
System.out.println("Thanks for playing game,see you next time!");
}
public static void sleep(int time) {
try {
Thread.sleep(time);
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}
 

Attachments

  • Capture.webp
    Capture.webp
    11.5 KB · Views: 21
Status
Not open for further replies.

About this Thread

  • 6
    Replies
  • 392
    Views
  • 2
    Participants
Last reply from:
Renzpbg

Trending Topics

Online now

Members online
585
Guests online
869
Total visitors
1,454

Forum statistics

Threads
2,282,305
Posts
29,007,678
Members
1,223,867
Latest member
Nikkopogi13111
Back
Top