Answers for "take string input using scanner java"

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
0

User input (scanner)

int age = scanner.nextInt();
scanner.nextLine(); //Ez fogja az ottmaradt sorvége jelet beolvasni
        
String name = scanner.nextLine();
Posted by: Guest on April-25-2021
-1

User input (scanner)

Scanner scanner = new Scanner(System.in);

System.out.println("What's your name?");
String name = scanner.nextLine();

System.out.println("What's your year of birth?");
int yearOfBirth = scanner.nextInt();
Posted by: Guest on April-25-2021

Code answers related to "take string input using scanner java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language