It seems like you're encountering a couple of issues in your code. Firstly, when comparing strings in Java, you should use the .equals() method instead of the == operator. So, instead of if (Awnser1 == "Yes"), you should write if (Awnser1.equals("Yes")). Similarly, for the comparison in the else if block.
Secondly, the reason for not indenting properly here might be due to how you pasted the code. Ensure that the indentation is consistent when you paste it into an editor or an online platform.
Here's the corrected version of the relevant parts of your code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Set Your Health");
int health = scanner.nextInt();
boolean IsAlive = health > 0;
if (IsAlive) {
System.out.println("Your Health Has Been Set To: " + health);
} else {
System.out.println("You Cannot Set Your Health To Negatives");
}
System.out.println("You Find A Legendary Sword. Do You Pick It up?");
String Answer1 = scanner.next();
if (Answer1.equals("Yes")) {
System.out.println("You Pick Up \"Xyronyth, The Tempests Embrace\" And Venture Onwards");
System.out.println("You Get Attacked By A Dragon And Draw Your Sword");
double ddmg = Math.random() * 17;
ddmg = Math.round(ddmg);
health -= ddmg;
if (IsAlive) {
System.out.println("You Took " + ddmg + " Damage");
System.out.println("You Attack The Dragon With Your Sword And It Dies");
} else {
System.out.println("You Died");
}
} else if (Answer1.equals("No")) {
System.out.println("You Leave The Sword Laying And Venture Onwards");
System.out.println("You Get Attacked By A Dragon, It would be Very Good If You Would Have Something To Defend Yourself with");
while (Answer1.equals("No")) {
double ddmg = Math.random() * 17;
ddmg = Math.round(ddmg);
health -= ddmg;
if (IsAlive) {
System.out.println("You Took " + ddmg + " Damage");
} else {
System.out.println("You Died");
}
}
}
}
}
This should fix the string comparison issue and provide better indentation for your code.
If you're still facing challenges with your Java assignment, remember that programming is often a journey of trial and error. Don't hesitate to seek assistance from various resources available online. From community forums to educational websites, there are plenty of places where you can find guidance and support to improve your coding skills. Whether you're grappling with string comparisons or tackling complex algorithms, every hurdle you overcome brings you one step closer to mastery. If you find yourself in need of additional
help with Java assignment, consider exploring reputable platforms like
programminghomeworkhelp.com that offer programming homework assistance. They can provide valuable insights and tips to enhance your understanding of the language. After all, in the world of programming, every bit of knowledge gained is a step towards becoming a proficient coder.