Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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 
Comment

java get input

Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = sc.nextInt();
double d = sc.nextDouble();
float f = sc.nextFloat();

// more fast way
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine(); // read line
int c = br.read();        // read single char
Comment

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();
Comment

how to read input in java

//For continues reading a line
import java.util.Scanner; 

Scanner in = new Scanner(System.in); 
while(in.hasNextLine()) {
   String line = in.nextLine();
   System.out.println("Next line is is: " + line); 
}
Comment

how to use input in java

import java.util.*;
class b
{
    void main ()
    {
        Scanner in = new Scanner(System.in);
      System.out.print("Please enter you age: ");
      int age = in.nextInt();
      System.out.print("Please enter today's date: ");
      int date = in.nextInt();
      System.out.print("Please enter current month: ");
      int month = in.nextInt();
      System.out.print("Please enter current year: ");
      int year = in.nextInt();
    }
}
Comment

java get input


import java.util.Scanner; 
//...
Scanner scan = new Scanner(System.in);
String s = scan.next();
int i = scan.nextInt();

Comment

how to input in java

import java.util.*; //or java.util.scanner
Scanner doit = new Scanner(System.in);//Name the scanner
System.out.println("Username:");//It will specify username
String username = doit.next();//Use scanner and add .next for string .nextInt for int and follows
Comment

get input in java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Sample {

    public static void main(String[] args) {
        BufferedReader datain = new BufferedReader(new InputStreamReader(System.in));
        String name = "";
        System.out.print("Enter your name:");
        try {
            name = datain.readLine();
        } catch (IOException e) {
            System.out.print("Error");

        }
        System.out.println("Hello! " + name + "!");
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: flutter remove last caracter from string 
Java :: random java 
Java :: java get file from url 
Java :: java go troght loop object 
Java :: action bar message spigot 1.8 
Java :: java hashmap key exists 
Java :: java how to cast int to String 
Java :: java how to check string is number 
Java :: swing button 
Java :: java observer pattern 
Java :: jframe change icon 
Java :: java list contains object with property 
Java :: java get number of threads 
Java :: how to get key value from json object in java 
Java :: java map to list or array 
Java :: java variable in string 
Java :: android list[i] 
Java :: A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution java.lang.reflect.InvocationTargetException (no error message) 
Java :: how to get input form combobox java 
Java :: iterable interface in java 
Java :: java loop over string 
Java :: running sum of 1d array java 
Java :: int array java 
Java :: initial data for list java 
Java :: Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: plugins.flutter.io/webview 
Java :: insert element into arraylist java 
Java :: Spring boot enable openapi swagger accessed 
Java :: how to convert int to string in java? 
Java :: java regex 
Java :: formatting an integer in java 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =