Answers for "string input in java"

34

how to take input in java

Scanner sc = new Scanner(System.in);  // Create a Scanner object
String userName = sc.nextLine();//read input string
int age = sc.nextInt(); //read input integer
long mobileNo = sc.nextLong(); //read input long
double cgpa = sc.nextDouble(); //read input double
System.out.println(userName);//output
Posted by: Guest on May-03-2020
38

scanner in java

import java.util.Scanner;		//Import Scanner in java

class classname{
  public void methodname(){
    Scanner s_name = new Scanner(System.in);	//Scanner declaration
    //Use Scanner object to take input
    int val1    =  s_name.nextInt();			//int
    float val2  =  s_name.nextFloat();			//float
    double val3 =  s_name.nextDouble();			//double
    string name =  s_name.nextLine();			//string
    char ch     =  s_name.nextLine().charAt(0);	//character
  }}
Posted by: Guest on May-25-2020
14

taking string input in java

Scanner in = new Scanner(System.in);
String s = in.nextLine();
Posted by: Guest on April-27-2020
2

java read string input

import java.util.Scanner;
 
public class YourClass {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String inputString = scanner.nextLine();
        System.out.println("Your string: " + inputString);
    }
}
Posted by: Guest on March-14-2020
3

java input character

import java.util.Scanner;
Scanner inp = new Scanner(System.in);
char character = inp.next().charAt(0);
Posted by: Guest on September-12-2020
7

how to input in java

import java.util.Scanner;
...
  Scanner console = new Scanner(System.in);
  int num = console.nextInt();
  console.nextLine() // to take in the enter after the nextInt() 
  String str = console.nextLine();
Posted by: Guest on January-05-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language