・ 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.
Of course it is not displayed because it is a comment.
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.
It feels like it's used properly depending on the situation.
-It seems that System.out.println () also causes line breaks.
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.
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