I am completely new and just recently started learning programming with Java. Along the way, there are most likely the simplest questions.

Screen 1. How to make the "test method" method have several passed parameters, not one X, but some more? It seems that you can write another line in parentheses, for example, y , which will add another phrase, but how then to send name to x , and sername to y ? Or I suspect that it is absolutely impossible to do this at all, and you need to write a separate method for y .

Screen 2. Why it is impossible to do this and what is the difference, if all my variables, etc. written inside the class, not inside the main method, please explain. The fact that the main method is the input point of each program, I understood, and everything begins with it.

Question 3. Please advise the literature that really helps get you started. It seems everywhere Java philosophy is advised.

Screen 1

enter image description here

Closed due to the fact that off-topic participants Kromster , freim , 0xdb , aleksandr barakin , Eugene Krivenja May 10 at 20:30 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - freim, Eugene Krivenja
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    Please replace your screenshots with real code inserted into the question. In order for a block of text to be displayed as a code, it must be separated by empty lines and have at least 4 spaces of indentation left - Sergey Nudnov pm
  • Books and tutorials on Java - Sergey Gornostaev 6:43 pm
  • This question should be closed, because it is very general and does not contain code in the form of text. - 0xdb

2 answers 2

1. You can pass up to 65k + arguments or use varargs to pass an indefinite number of arguments of the same type.

 public String method(String s1, String s2) { return s1 + s2; } 
  1. Expressions should be inside methods, but variable definitions can find inside classes and inside methods.
    If you want to specify an initial value for a variable, specify it when declaring or assign a value in the class constructor.

Update

The fact that you in the probniyMethod method assign x new value will make it visible only inside the method. Similar question.
If you need to change several arguments with a function, wrap them in a class, implement getters and setters .

 class Main { public static void main(String args[]) { Data d = new Data("s1", "s2") System.out.println(d.getS1()); System.out.println(d.getS2()); changeData(d); System.out.println(d.getS1()); System.out.println(d.getS2()); } private static changeData(Data data) { data.setS1(data.getS1() + ", changed") data.setS2(data.getS2() + ", changed") } } class Data { private String s1; private String s2; public Data(String s1, String s2) { this.s1 = s1; this.s2 = s2; } public String getS1() { return s1; } public void setS1(String s) { s1 = s; } public String getS2() { return s2; } public void setS2(String s) { s2 = s; } } 

PS Read about inheritance , polymorphism , encapsulation

  • Arguments passed, and how now to direct one line to one argument, and the second to another? (i.e., sername on x, and name on the new argument y), how to write this correctly? - jewbaka
  • @jewbaka updated the answer - Bleser

Why it can not be done and what is the difference if all my variables, etc. written inside the class, not inside the main method, please explain.

In the method main variables are local to this method. In a class, variables belong to classes. When you create an instance of a class, the method refers to an instance, an object of your class.

Read Java philosophy after more simple books. At the initial stage of training you will be difficult to understand certain concepts. Take something simpler. Do not immediately read the works of eminent scientists. It will be difficult for you to understand their thoughts. If you understand, it will be difficult for you to communicate with recruits and technical staff who do not understand this.