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

input java

import java.util.Scanner;

class Input {
    public static void main(String[] args) {
    	
        Scanner input = new Scanner(System.in);
    	
        System.out.print("Enter an integer: ");
        int number = input.nextInt();
        System.out.println("You entered " + number);

        // closing the scanner object
        input.close();
    }
}
Comment

input java

Scanner in = new Scanner(System.in);
      System.out.print("Please enter hour 1: ");
      int hour1 = in.nextInt();
      System.out.print("Please enter hour 2: ");
      int hour2 = in.nextInt();
      System.out.print("Please enter minute 1: ");
      int min1 = in.nextInt();
      System.out.print("Please enter minute 2: ");
      int min2 = in.nextInt();
Comment

input java

import java.util.Scanner;

class Input {
    public static void main(String[] args) {
    	
        Scanner input = new Scanner(System.in);
    	
        // Getting float input
        System.out.print("Enter float: ");
        float myFloat = input.nextFloat();
        System.out.println("Float entered = " + myFloat);
    	
        // Getting double input
        System.out.print("Enter double: ");
        double myDouble = input.nextDouble();
        System.out.println("Double entered = " + myDouble);
    	
        // Getting String input
        System.out.print("Enter text: ");
        String myString = input.next();
        System.out.println("Text entered = " + myString);
    }
}
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 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

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

PREVIOUS NEXT
Code Example
Java :: play sound on button click android studio 
Java :: char variable java 
Java :: spring enable cors 
Java :: java main class 
Java :: hashtable contains key java 
Java :: java create list of strings 
Java :: hashmap.foreach example 
Java :: Multiply two Strings Leetcode 
Java :: java load .json file 
Java :: retrofit dependency in android studio 
Java :: how to get the last element of array in java 
Java :: java string format 2 decimal places 
Java :: read csv java android 
Java :: java.lang.ExceptionInInitializerError: null 
Java :: get file dimension java 
Java :: resource leak java 
Java :: json date format for localdate java 
Java :: how to check grant permissions in android 
Java :: java 2d array loop 
Java :: spring boot intellij auto reload 
Java :: get month from int java 
Java :: change height of row at JTable 
Java :: how to wait in java 
Java :: factorial of a number using recursion in java 
Java :: java 16 raspberry pi 
Java :: android splash screen 
Java :: java random unique number 
Java :: java jframe example 
Java :: java 8 list stream delete by name 
Java :: how to create a stack data structure in java? 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =