Answers for "scanner java methods"

84

java scanner

import java.util.Scanner;

// import scanner 

Scanner myScanner = new Scanner(System.in); // Make scanner obj

String inputString = myScanner.nextLine(); // Take whole line

boolean inputBoolean = myScanner.nextBoolean(); //Boolean input

long inputLong = myScanner.nextLong(); //Interger,long ... input
Posted by: Guest on November-26-2019
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
1

static scanner java

import java.util.Scanner;


class ComputerScienceHomework16 {
  // making it static in other functions
  static Scanner scanner = new Scanner(System.in);
  
  public static void test(){
    System.out.print("type a number: ");
    int num = scanner.nextInt();
    System.out.println("you typed the number " + num);
  }
  
  public static void main(String[] args) {
    test()
    
  }
}
Posted by: Guest on March-20-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language