Data Structures Lab1 2020 Ce 118 PDF
Data Structures Lab1 2020 Ce 118 PDF
LAB: 1
TASK: 1
Write a program that take string as an input attempting to guess the secret word enters
letters one at a time. After each guess, the guess template is updated (if necessary) to show
which letters in the secret word match the letter guessed. This process continues until the
guess template matches the secret word choice of 7 wrong attempts. The number of
guesses is then output.
CODE:
m
er as
package guess;
co
eH w
import java.util.Scanner;
o.
public class guess {
rs e
ou urc
public static void main(String[] args) {
int tries = 0;
o
aC s
do {
System.out.println("Guess a letter");
sh
https://www.coursehero.com/file/85064299/DATA-STRUCTURES-LAB1-2020-Ce-118pdf/
M.UMER AHSAN 2020—CE-118
if(!iterated)
temp += Character.toString(word.charAt(i));
else {
holder = Character.toString(temp.charAt(i)).replace("-", guess);
temp = temp.substring(0, i) + holder + temp.substring( i + 1, temp.length());
}
else{
if(!iterated) {
temp += "-";
m
er as
}}
co
eH w
}
o.
tries++; rs e
ou urc
iterated = true;
System.out.println(temp);
o
aC s
if(temp.equals(word)) {
vi y re
}
}
is
{System.out.println("Game Over");}
}}
sh
https://www.coursehero.com/file/85064299/DATA-STRUCTURES-LAB1-2020-Ce-118pdf/
Powered by TCPDF (www.tcpdf.org)