Как мне вернуться к основному методу?
я вложил в него свой код
вернуть;
но он не возвращается к основному методу
Что я уже пробовал:
import java.util.Random; // Random number generator class import java.util.Scanner; // reads user inputs public class HiLo { private static Scanner input = new Scanner(System.in); public static void main (String[] args) { System.out.print("Rules"); System.out.println("Number 1 through 6 are low"); System.out.println("Number 7 are neither"); System.out.println("Number 8 through 13 are high"); System.out.println("You have 1000 points"); number(); } public static void number() { System.out.println("Predict(1=high, 0=low): "); int guess = input.nextInt(); System.out.println("Enter the points to risk: "); int risk = input.nextInt(); int points = 1000; switch(guess) { case 1: high(guess,risk,points); break; case 2: low(guess,risk,points); break; } } public static void high(int guess, int risk, int points) { final int max = 13; int answer; Random generator = new Random(); //Random number generator. 0 to 10. answer = generator.nextInt(max) +1; if(guess!= answer) { System.out.println("Number is " + answer); System.out.println("you lose."); int total = points - risk; System.out.println("you have " + total + " points"); System.out.println("play again?(1 for yes, 2 for no)"); int playagain = input.nextInt(); if(playagain == 1) { return; } if(playagain == 2) { System.out.println("GG"); } } if(guess == answer) { System.out.println("Number is " + answer); System.out.println("you win."); int total = points + risk; System.out.println("you have " + total + "points"); System.out.println("play again?(1 for yes, 2 for no)"); int playagain = input.nextInt(); if(playagain == 1) { return; } if(playagain == 2) { System.out.println("GG"); } } } public static void low(int guess, int risk, int points) { final int max = 13; int answer; Random generator = new Random(); //Random number generator. 0 to 10. answer = generator.nextInt(max) +1; if(guess!= answer) { System.out.println("Number is " + answer); System.out.println("you lose."); int total = points - risk; System.out.println("you have " + total + " points"); System.out.println("play again?(1 for yes, 2 for no)"); int playagain = input.nextInt(); if(playagain == 1) { return; } if(playagain == 2) { System.out.println("GG"); } } if(guess == answer) { System.out.println("Number is " + answer); System.out.println("you win."); int total = points + risk; System.out.println("you have " + total + "points"); System.out.println("play again?(1 for yes, 2 for no)"); int playagain = input.nextInt(); if(playagain == 1) { return; } if(playagain == 2) { System.out.println("GG"); } } } }
Richard MacCutchan
Да, это так, и main немедленно прекращается.
Nerdy4dayz
почему? и как я могу это исправить?
Richard MacCutchan
Что ты имеешь в виду "причина"- а что вы хотите исправить?