Pages

Wednesday, October 7, 2015

Java most beginner tutorial use of scanner object..how to get input from user

Assalam-o-alaikum !

JAVA MOST BEGINNER PROGRAMMING

   how to take input from user using scanner


package scanner;

import java.util.Scanner;

/*scanner import belong to util library*/

public class example{

/*keep in mind you can declare the variable in the main function as well as out of main ...if you wanna make it out from the main so you just put static from the scanner object like this*/

Static Scanner input = new Scanner(System.in);
/* what we did up here is first we created a scanner object.its  out of main function so we made it static ...static mean we can access it from any where...and as a parameter it take System.in ..so you should put that.because you wanna input from the user .*/

/*and now import your scanner you can import it by typing Ctr+shift+o from your keyboard or just hover your mouse on scanner and it will automatically pop up scanner import for you..and you just press on it*/


public static void main (String[]args){

System.out.println("what's your name?");

/*It's mean you gave an output to the user.you asked his name.now this is the time to use Scanner object.so we have given our Scanner name input .now give users a line to type something in it like this
*/
input.nextLine();

/* it's mean user can type text in the next line,and right now if you want to store the user input.so you can do it.Just create a String variable.like this*/
String storeUserInput;
storeUserInput = input.nextLine();
/*so now if anything a user would type ..it will store into our storeUserInput variable ,now if you want to show them their text back.do like this*/

System.out.println(storeUserInput);



 }


}
all your activities will look like this


and now if you run this it would ask about your name if you enter your name so it will then look like this



i hope you got the idea if you wanna watch tutorial about this visit me on


to catch more of me like subscribe and share with your friends

Sunday, October 4, 2015

Java beginner programming declaring variable and describing data type

                      java most beginner tutorial 


                Data types ,variable    



public class{
public static void main(String[]args){ 


/*to declare variable these are the codes make sure  to spell them 

correct other wise it wont work*/  

// to declare int 

int ab = 33; 


/* you can't initialize any decimal value or text in an int.other wise it
would give an error..so being very careful.. for the decimal value there

 is a specific data type called double  ..so if you need to have some decimal 

values in java so you can  declare them with double like below*/  


double aa = 33.33;



/* so string is actually use for text values like if you wanna print out

some text with variable so you can do this thing like below*/ 



String ac = "how are you";

         System.out.println(ab);

System.out.println(aa);

         System.out.println(ac);



/*now if you wanna change your int to string so below is the process*/  


int d = 39;
String e=Integer.toString(d);
System.out.println(e); 



/*if you wanna change your String into int or double so the process is below */ 

String f ="44"; 


int g = Integer.parseInt(f);
System.out.println(g);

 //you cant change text value to int so thats the point

/*how to get the maximum value of an int double or float */ 


System.out.println(Integer.MAX_VALUE);
System.out.println(Double.MAX_VALUE);
System.out.println(Float.MAX_VALUE); 

 /*how to get minimum value*/ 



System.out.println(Integer.MIN_VALUE);
 

}

}



To watch video for this click me