Hi, I will be giving a class on java programming,
Today in our first lesson we are going to review/learn some printing statements, for loops and if statements.
First of all lets start by the software that we will be using for our class.
Then we will have to download the java SDK:
Download Java SDK
To create a new project in IntelliJ, we click on, create new project ( the first time the project needs to be aligned with java sdk).
Then we create a package, and afterwards a java class usually with the same name of the package. It will be assigned a default constructor.
In order for the java program to run, there should be a main static method.
We will be using the scanner class today, that must be imported with:
Below there is an example for the lesson of today:
Printing to the screen:
Comments can be done by using:
// for one line
***** For beauty
It's always good to have documentation, name of the the program with extension, name of the author, the date and what the program does. under the import statements.
Today Practice programs:
1- Create a program that asks user for name and then prints out the name + how are you?
2- Create Sum the numbers from 1 to 10 using for loops
3- Create program that takes an integer input from user and if the integer is positive prints "positive"x3, if it's negative it prints"negative"x4 and if it's zero, print neutral. Use For loops and if statements.
Indentation is needed for readability.
white space between the things that don't belong to a group.
Meaningful names will give you a description of the purpose of the the object/class/method/variable.
When naming variable in java, the camel style is the way to go, start with lowercase then change to Uppercase if it's a combination of words, e.g. myNumber. don't use under bars, but if wanting to use under bars, put all letters in capital, MY_NUMBER.
For Class names use Uppercase, MyClass.
For methods start with lowercase. myMethod.
For Homework submission email to:
Homework # 1 -
Create 3 different programs:
1- Ask the user for 3 inputs. Then you will decide which input is larger than the other.Then you print out the largest.
2-Reverse string in 2 different ways.
3-Do the Palindrome in 2 different ways.