NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io


import java.util.Scanner;

public class Assign8 {

public static Scanner numscan = new Scanner(System.in);
public static Scanner wordscan = new Scanner(System.in);

public static void main(String[] args) {

String word;
System.out.println("Please enter a word of any length to be guessed.");
word = wordscan.nextLine();
String[] Chars = word.split("");

int length = 0;

for (int i = 0; i < Chars.length; i++) {

length++;

}//end for

String[] Guess = new String[length];

String[] complete = new String[length];

int error = 0;

boolean done = true;

while (done) {

boolean doner = false;

System.out.println(" ");
String ans;
System.out.println("Guess one letter.");
ans = wordscan.nextLine();

boolean match = contains(ans, Chars);

int trues = 0;

if (match == false) {

error++;

} else if (match == true) {

doner = true;

for (int i = 0; i < Chars.length; i++) {

if (ans.equals(Chars[i])) {

complete[i] = ans;

}//end if

}//end for

for (int i = 0; i < Chars.length; i++) {

if (Chars[i].equals(complete[i])) {

Guess[i] = complete[i];

} else {

Guess[i] = "_";
trues++;

}//end if

}//end for

}//end if

System.out.println(draw(error));

for (int i = 0; i < Guess.length; i++) {

System.out.print(Guess[i] + " ");

}//end for

System.out.println(" ");

if (error == 7) {

done = false;
}//end false

if (doner == true) {

if (trues == 0) {

done = false;
System.out.println(" ");
System.out.println("Congratulations!");

}//end if

}//end if

}//end while

}//end main

public static boolean contains(String word1, String[] word2) {
boolean match = false;
for (int i = 0; i < word2.length; i++) {
if (word2[i].contains(word1)) {

match = true;

}//end if
}//end for
return match;

}//end Contains

public static String draw(int error) {
String drawing = null;

if (error == 0) {

drawing = " n"
+ "-------------n"
+ " n"
+ " n"
+ " n";

} else if (error == 1) {

drawing = "-------------n"
+ " |n"
+ " n"
+ " n"
+ " n";

} else if (error == 2) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " n"
+ " n";

} else if (error == 3) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " / n"
+ " n";

} else if (error == 4) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " / | n"
+ " n";

} else if (error == 5) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " / | \ n"
+ " n";

} else if (error == 6) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " / | \ n"
+ " / n";

} else if (error >= 7) {

drawing = "-------------n"
+ " |n"
+ " O n"
+ " / | \ n"
+ " / \ n"
+ "I am sorry, you lose.";

}

return drawing;

}//end draw

}//end class
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.