input of string in java code example
Example 1: scanner in java
import java.util.Scanner;
class classname{
public void methodname(){
Scanner s_name = new Scanner(System.in);
int val1 = s_name.nextInt();
float val2 = s_name.nextFloat();
double val3 = s_name.nextDouble();
string name = s_name.nextLine();
char ch = s_name.nextLine().charAt(0);
}}
Example 2: how to take input in java
Scanner sc = new Scanner(System.in);
String userName = sc.nextLine();
int age = sc.nextInt();
long mobileNo = sc.nextLong();
double cgpa = sc.nextDouble();
System.out.println(userName);