Studying Java ―― 2

Insert comment

・ For one line, "//" ・ For multiple lines, enclose the front and back with "/ * * /"

Yomogi.java


public class Yomogi{
    public static void main(String[] args){
		
		//1 line comment
        
		System.out.println("Hello, world.");
		
		/*
For multiple lines
* You can use it in one line.
		*/
		
    }
}

When you do this.

pic002.JPG

Of course it is not displayed because it is a comment.

Difference between print and println

Roughly speaking, the difference is whether or not there is a line break at the end of the line?

・ Print ⇒ No line break at the end of the line ・ Println ⇒ There is a line break at the end of the line ・ "\ N" to explicitly insert a line break

Yomogi.java


public class Yomogi{
    public static void main(String[] args){
		//When printing
		System.out.print("Hello, ");
		System.out.print("world.\n");
		
		//When println
		System.out.println("Hello, ");
		System.out.println("world.");
    }
}

Run it and see the difference.

pic003.JPG

It feels like it's used properly depending on the situation.

-It seems that System.out.println () also causes line breaks.

Use variables and output numbers

My knowledge of math has disappeared so much that I couldn't remember the meaning of integers. For the time being, I was convinced that it was not a decimal point.

-Variables for using integers seem to be "int" -Use "=" to enter a numerical value in a variable

So, by defining an integer variable a in the uninflected word Enter an appropriate value and see the output result.

Yomogi.java


public class Yomogi{
	public static void main(String[] args){
		int a;		
		a = 12;
		
		System.out.println("Numerical output");
		System.out.println(a);
		System.out.println(34);
	}
}

And execute.

pic004.JPG

I didn't notice it when I output the string

-In the case of a character string in println or print, it is necessary to add "" "before and after. -In the case of variables and numerical values, "" "seems unnecessary.

Well, I wonder if that recognition is okay now. A stance of lowering hurdles to continue studying.

This time up to here.

Recommended Posts

Studying Java ―― 3
Studying Java -5
Studying Java ―― 1
Studying Java # 0
Studying Java ―― 8
Studying Java ②
Studying Java ―― 7
Studying Java ―― 2
Studying Java ①
Studying Java -10
Studying Java 8 (Optional)
Studying java9 (jShell)
Studying Java 8 (Stream)
Studying Java 8 (Collector / Collectors)
Studying Java 8 (see method)
Studying Java 8 (see constructor)
Java
Studying Java ~ Part 8 ~ Cast
Studying Java 8 (lambda expression)
Java learning (0)
[Java] array
[Java] Annotation
[Java] Module
Java array
Java tips, tips
Java methods
Java method
java (constructor)
Java array
[Java] ArrayDeque
java (override)
java (method)
Java Day 2018
Studying Java # 6 (How to write blocks)
java (array)
Java static
Java serialization
JAVA paid
Java (set)
java shellsort
java reflexes
java (interface)
Java memorandum
☾ Java / Collection
[Java] Array
[Java] Polymorphism
Java review
java framework
Java features
Java features
java beginner 3
Java memo
java (encapsulation)
Java inheritance
[Java] Overload
Java basics
Decompile Java
[Java] Annotation
java notes
java beginner
Java (add2)