Полный пример программы с забавным поворотом:
Откройте новый пустой документ и сохраните его как %yourJavaDirectory%/iAmABoy/iAmABoy.java
.«iAmABoy» - это имя класса.
Вставьте следующий код и прочитайте его.Помните, я новичок, поэтому я ценю все отзывы!
//The class name should be the same as your Java-file and directory name.
class iAmABoy {
//Create a variable number of String-type arguments, "strs"; this is a useful line of code worth memorizing.
public static void nlSeparated(String... strs) {
//Each argument is an str that is printed.
for (String str : strs) {
System.out.println(str);
}
}
public static void main(String[] args) {
//This loop uses 'args' . 'Args' can be accessed at runtime. The method declaration (above) uses 'str', but the method instances (as seen below) can take variables of any name in the place of 'str'.
for (String arg : args) {
nlSeparated(arg);
}
//This is a signature. ^^
System.out.print("\nThanks, Wolfpack08!");
}
}
Теперь в терминале / cmd перейдите к %yourJavaDirectory%/iAmABoy
и введите:
javac iAmABoy.java
java iAmABoy I am a boy
Вы можете заменитьАрги I am a boy
ни с чем!