5. INPUT

Hi friends what's up.I hope you are well.In last tutorial we are learning about if-else statement.Today we will learning how to take input from keyboard.

First we see a code which can take input..........
take a class named inputt.


import java.util.Scanner;
public class inputt {
      public static void main(String args[]){
     Scanner pavel = new Scanner(System.in);
     
     String Mostafij = pavel.nextLine();
     System.out.println(Mostafij);
      }
}


output

Hi I love you                                    (that's i input from keyboard)

Hi I love you
Here we make a class named inputt. At the top we import  java.util.Scanner.It is very important.
then we take a Scanner variable pavel and initialized as new Scanner input. Then we take a String variable Mostafij & initialized in by what we input from keyboard.For taking String we have to wright Scanner_variable.nextLine().


for int variable



import java.util.Scanner;
public class inputt {
      public static void main(String args[]){
       Scanner pavel = new Scanner(System.in);
       
       int Mostafij = pavel.nextInt();
       System.out.println(Mostafij);
      }
}



For taking integer we have to wright Scanner_variable.nextInt().

for float variable
import java.util.Scanner;
public class inputt {
      public static void main(String args[]){
       Scanner pavel = new Scanner(System.in);
       
       float Mostafij = pavel.nextFloat();
       System.out.println(Mostafij);
      }
}
For taking float we have to wright Scanner_variable.nextFloat().
for double variable
import java.util.Scanner;
public class inputt {
      public static void main(String args[]){
       Scanner pavel = new Scanner(System.in);
       
       float Mostafij = pavel.nextFloat();
       System.out.println(Mostafij);
      }
}
For taking idouble we have to wright Scanner_variable.nextDouble().

Here it is........end.See you in next tutorial.Till then be safe.

Penulis : Mostafij ~ Sebuah blog yang menyediakan berbagai macam informasi

Artikel 5. INPUT ini dipublish oleh Mostafij pada hari Tuesday, April 9, 2013. Semoga artikel ini dapat bermanfaat.Terimakasih atas kunjungan Anda silahkan tinggalkan komentar.sudah ada 0 komentar: di postingan 5. INPUT
 

0 comments:

Post a Comment