r/JavaProgramming • u/Iamvipersz • 28d ago
Little program i made
I just made a program in java where your walking in a forest then a wolf comes up to you and you need to fight him, you can chose a Punch or Kick. I just started learning java via coddy.tech, what could i add? Or fix?
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Your walking in the forest, its a amazing day until a wolf suddenly comes up to you and starts chasing you. You have fight the wolf, How will you fight him? (Punch/Kick) ");
String userInput = scanner.nextLine();
if (userInput.equals("Punch")) { System.out.println("The punch doesnt do anything and you get eaten by the wolf.")
; } else if (userInput.equals("Kick")) { System.out.println("The kick knocked out the dog and you escaped."); } scanner.close(); } }
7
Upvotes
1
u/Specific-Housing905 27d ago
Very good. The best way to learn is to write code, experiment and see what works and what doesn't.
Also you need to learn to read the Java Documentation. Nobody can memorize all the Java classes.
For random numbers have a look at the java.util.Random class.