A junior high school student who started learning IT from the fifth grade of elementary school. The first language I learned was "C language" (laughs) Looking for a job! Languages that can be handled C language HTML & CSS (studying) Python (studying) Ruby (studying) Java (studying) You can make some things As I say many times, we are looking for a job!
Java is a language used for various purposes such as application and web development.
main.java
System.out.println("");
Output a string with this function What I thought here was "It's similar to the syntax of C language"
That's right!
Java was also designed to make it easier for c programmers to migrate! (Thank you) So the syntax rules came in smoothly! Highly recommended as a second for those who have learned c language
main.java
//comment
Write the comment like this (also used in C) //でそのあとにコメントを書きます Be careful when writing comments, but when writing comments ・ Briefly ・ Easy to understand ・ Use where you think "it's hard to understand ..." I am aware of these three I like all the codes that are easy to read!
Next is about "variables", which is not an exaggeration to say that they are always used in programming. --What are variables in the first place? --- A variable is like a box that can hold data. As anyone who uses C language will understand, you may have thought, "I have to think about memory quite a bit." And the c language declaration is confusing ... However, as I said earlier, Java is also made to be easy for c programmers to migrate, so the declaration is almost the same.
main.c
int num;
double piyo;
In C language, to declare the variable num of int, write like this And to declare the double variable piyo, write So next is Java
main.java
int num;
Double piyo;
Yes. That's right. The only difference is whether the double d is lowercase or uppercase when declaring a double variable ... But well, it's easier to understand if you're used to this one. To be honest, I was surprised when I first saw the Python declaration.
main.py
num = 3
piyo = "qiita"
Depending on the language difference, it seems that the data is assigned as it is when declaring. Like Ruby.
Asterisk (*) when multiplying numbers Hyphen (-) when pulling Slash when dividing (/) Plus (+) when adding Percentage (%) when giving a remainder
How to write an abbreviation when self-assigning to a variable Assuming that an int type variable x is defined
Uninflected word x = x + 10; x = x - 10; x = x * 10; x = x / 10; x = x % 10;
Abbreviation x += 10; x -= 10; x++; x--; x *= 10; x /= 10; x %= 10;
It was pretty refreshing Here, it is important to note that when writing self-assignment in abbreviation, "write the operator first". And x ++ is an abbreviation for 1+. It is often used for conditional branching called if statement.
Use println () to print the value of the variable I will introduce all of them
main.java
int num;
Double piyo;
num = 1;
piyo = "qiita!";
System.out.println(num);
System.out.println(piyo);
System.out.println("Hello" + "qiita!");
System.out.println("Hello" + piyo);
System.out.println((double)piyo + "I'm a grader");
You can see the first one. Print the values of num and piyo with println () Below that, + is used to output the character strings together. Of course, it can also be concatenated with variables. However, if you enclose the variable in double quotation marks ("), it will be displayed as a character string instead of the variable, so be careful! At the end, int type (integer type) cannot be concatenated with a character string, so it is converted to double type (character string type) and displayed. This is a technique I often use!
-Java is similar to the C language syntax because it is also designed to be easy for C programmers to migrate. -Use println () to output a string ・ Comment starts at // -When declaring a variable, declare the type first. ・ Character strings can be connected to each other -To concatenate an int type and a character string, the int type must be converted to a double type. -Self-assignment has an abbreviated form
Thank you so much for watching I'm still immature, so if you have any suggestions, please I'm on Twitter: https://twitter.com/Atie44675100 I'll say it over and over again, but I'm looking for a job!
Recommended Posts