Classes are like blueprints. java creates a program in units called classes. When writing, write the class name on the right side of "class" and enclose it in {} (block).
class Hello{
public static void main(String[] args) {
System.out.println("Hello World");
}
Variables are like boxes that you name and temporarily store data attributes. There are two main types of variables.
** Basic type (basic data type / primitive type) ** There are 8 types. Basic type variables manage their values directly.
** Class type (reference type) ** Infinite. (There are as many classes as there are.) There is a variable of class type ... that means that the class exists. A class type variable manages a copy (address) of that class. Also, write the first letter of the class in uppercase.
A med is an instruction to execute a program.
When you enter the name,
import java.util.Scanner;
class BackHome{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
System.out.print("Tell me your name:");
String s = stdIn.next();
System.out.println("Welcome, home" + s + "Sama");
}
}
** Input procedure 1 ** Preparation for using the Scanner class.
import java.util.Scanner;
** Input procedure 2 ** The variable "scanner" for using the Scanner class is being initialized.
Scanner stdIn = new Scanner(System.in);
** Class creation assignment **
String s = stdIn.next();
output (If you specify the variable s, you can use the character string that follows the address in it.)
System.out.println("Hello" + s + "!!");
Recommended Posts