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 :: print statement in java 
Java :: hashmaps java 
Java :: how to add textview to listview in android 
Java :: java check if property exists in class 
Java :: how to initialize a string in java 
Java :: java question mark operator 
Java :: selection sort java 
Java :: arrays.sort with comparator 
Java :: icon share android 
Java :: remove duplicates from string in java 
Java :: android studio remove button onclick 
Java :: regular expression java 
Java :: rock paper scissors java 
Java :: jasypt-spring-boot 
Java :: remove empty elements from array java 
Java :: can i run script in ubuntu using java 
Java :: power-hungry foobar solution in java 
Java :: pass array to method java 
Java :: Java get color from rgb values 
Java :: maximum arrays size in java 
Java :: flutter unable to find bundled java version 
Java :: jdbc dependency 
Java :: debug cxf 
Java :: sorting methods in java 
Java :: how to set java path in windows 10 
Java :: java calcuate milliseconds since 1970 
Java :: Sending String from one activity to another 
Java :: Implementing the Vector Class in java list 
Java :: how to develop web apps using java 
Java :: check if two lists are equal java 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =