Coding essentials and Java Input
Submitted by moazkhan on Wednesday, February 11, 2015 - 07:50.
Coding essentials and Java Input
In this tutorial you will learn: 1. Some coding essentials 2. Taking input in java console 3. Basic JAVA console program on conditional statements I have setting up the IDE now it’s time to start coding. The learning curve will be a little steep as we have much to cover. Some Coding Essentials This perhaps one of the most important things while programming in any language. There are a few main practices that every programmer must follow: 1. Indentation: To make your code more understandable indentation is a must. Try to balance the braces and statements. Try to use tab spaces and new lines as much as possible. You have a lot of free space so try your best to make your program neat. For example- If(statement){
- }
- Else{
- }
- }
- // single line comments
- /* If(){
- }
- Else{ }
- */
Basic Java console program:
• Open Eclipse > Workspace
• File > new > java project
• File > new > class
Write the following program
- import java.util.Scanner;
- public class Input {
- int num;
- char choice;
- float decimal;
- String name;
- num = inputScanner.nextInt(); //integer input
- choice = inputScanner.next().charAt(0); //character input
- decimal = inputScanner.nextFloat(); //float input
- name = inputScanner.next(); //string input
- //simply priting values
- }//end main
- }//end class
nextInt()
for integer, next().charAt(0)
for characters, next()
for strings. Then we are simply displaying these values to check whether the variables got the required input or not.
We will learn more coding in next tutorials.
If you have any questions or want to learn programming from me simply add me on skype
Username: mkprogrammer2121
Add new comment
- 42 views