Answer the question
In order to leave comments, you need to log in
[Outdated] What is wrong in my java code?
public class Main {
After these lines, I start setting variables that are used in various methods (so as not to constantly create the same variable).
There I created a variable in , which is responsible for entering data from the console.
And also:
Subsequently, in order to consider the answer (for example, Yes), I will write like this:
And now imagine this picture:static Scanner in = new Scanner(System.in);
static String answer = "";
answer = in.nextLine();
public static int Name1() {
System.out.println("Yes or No?");
answer = in.nextLine(); //Я ввожу Yes
//Там дальше код, который возвращает переменную (не answer)
}
public static int Name2() {
int whileStop = 0;
while (whileStop = 0) {
System.out.println("Da or Net?");
answer = in.nextLine();
if (answer.equals("Da") {
// Что-то написано
whileStop = 1;
} else if (answer.equals("Net") {
// И тут что-то написано
whileStop = 1;
} else {
System.out.println ("ERROR");
}
}
//Там дальше код, который возвращает переменную (не answer)
}
public static void main(String[] args) {
Name1();
Name2();
}
Yes or No?
Yes
Da or Net?
Da or Net?
answer = in.nextLine();
public static int Name1() {
System.out.println("Yes or No?");
answer = in.nextLine(); //Я ввожу Yes
//Там дальше код, который возвращает переменную (не answer)
}
public static int Name2() {
int whileStop = 0;
while (whileStop = 0) {
System.out.println("-- \n" + answer + "-- \nDa or Net?");
answer = in.nextLine();
if (answer.equals("Da") {
// Что-то написано
whileStop = 1;
} else if (answer.equals("Net") {
// И тут что-то написано
whileStop = 1;
} else {
System.out.println ("ERROR");
}
}
//Там дальше код, который возвращает переменную (не answer)
}
public static void main(String[] args) {
Name1();
Name2();
}
Yes or No?
Yes
--
Yes
--
Da or Net?
Da or Net?
Answer the question
In order to leave comments, you need to log in
after all, a variable cannot so easily get over from one method to another without return and parameters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question