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
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
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.
0 comments:
Post a Comment