answersLogoWhite

0


Best Answer

Scanner scan = new Scanner(System.in); // A scanner object that reads from the

// keyboard( System.in), must import

//Scanner class to use this System.out.print("Input Integer: "); int first = scan.nextInt(); //Reads the next int after the printed stuff that the user

//inputs System.out.print("Input Double: "); double first = scan.nextDouble(); //Reads the next double after the printed stuff that

//the user inputs

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you accept an integer or a float or double value as a console input from user in java also you do not want to use command line arguments?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What are the types main to accept command line arguments?

there are only one type ie main( int argc , int argv[]).


What is java command?

A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run.


Can a Java program use one or more command line arguments?

Command line arguments in Java are, as with most programming languages, a way to give information to a program at the point of invoking (starting to run) that program. The information is given in the form of a text string. Command line arguments are accessible in a Java program as an array of String objects passed into the program's "main" method. Unlike some programming languages (such as C/C++), where the command used to invoke the program is passed into the first array location (index 0) and the arguments subsequently, in Java the first argument occupies index 0. Command line arguments are a useful way of gathering information from the user when it is likely will know the information at the start of the program. For example, a Java application might copy a file from myFile.txt to myNewFile.txt by running the command "java CopyUtil myFile.txt myNewFile.txt". It is useful to allow such information to be passed in via command line arguments to make the program more scriptable: in other words, more conducive to scripted invocation, through a Desktop shortcut, through a batch file, through a shell script, etc.


Which header file is used to develop a function that can accept variable number of arguments?

.If you want to accept variable no of arguments then you have to include which of the following header files a) Vararg.h b) stdarg.h c) stdlib.h d) stdioh


What is a no args constructor?

No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.No args means no arguments. Just like any regular method, a constructor can have zero or more arguments.

Related questions

Definition of commandline arguments?

Hii I am Ajay Kumar MCA Student A Java application can accept any number of arguments from the command line. The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run.


What are the types main to accept command line arguments?

there are only one type ie main( int argc , int argv[]).


What is java command?

A Java application can accept any number of arguments from the command line. This allows the user to specify configuration information when the application is launched.The user enters command-line arguments when invoking the application and specifies them after the name of the class to be run.


Why does Java accept any input as string by default?

Java doesn't always accept any input as a string it only do that when the input is entered from the " JOptionPane.InputDialog" but it can accept any other data type like integer or short from the console though Scanner class .


Can a Java program use one or more command line arguments?

Command line arguments in Java are, as with most programming languages, a way to give information to a program at the point of invoking (starting to run) that program. The information is given in the form of a text string. Command line arguments are accessible in a Java program as an array of String objects passed into the program's "main" method. Unlike some programming languages (such as C/C++), where the command used to invoke the program is passed into the first array location (index 0) and the arguments subsequently, in Java the first argument occupies index 0. Command line arguments are a useful way of gathering information from the user when it is likely will know the information at the start of the program. For example, a Java application might copy a file from myFile.txt to myNewFile.txt by running the command "java CopyUtil myFile.txt myNewFile.txt". It is useful to allow such information to be passed in via command line arguments to make the program more scriptable: in other words, more conducive to scripted invocation, through a Desktop shortcut, through a batch file, through a shell script, etc.


How do you accept an integer or a float or double value as a console input from user in java also you do want to use command line arguments?

This code block will accept input from standard input (console). It will first read in integers until you enter an empty string (just hit enter). Then it will do the same with floats and then with doubles. If you give it bad input, then it will tell you about it and just continue reading in numbers. Note that I didn't touch the command line here, but the process to parse an argument sent in from the command line is the same as below. Just use the try-catch block with args[n] (in place of currentLine) to parse the nth argument. // create an BufferedReader from the standard input stream BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String currentLine = ""; // read integers System.out.print("Input an integer: "); while (!(currentLine = in.readLine()).equals("")) { int input = 0; try { input = Integer.parseInt(currentLine); } catch (final NumberFormatException ex) { System.out.println("That was not an integer."); } System.out.println("\tInteger read: " + input); System.out.print("Input an integer: "); } // read floats System.out.print("Input an float: "); while (!(currentLine = in.readLine()).equals("")) { float input = 0.0f; try { input = Float.parseFloat(currentLine); } catch (final NumberFormatException ex) { System.out.println("That was not an float."); } System.out.println("\tFloat read: " + input); System.out.print("Input an float: "); } // read doubles System.out.print("Input an double: "); while (!(currentLine = in.readLine()).equals("")) { double input = 0.0; try { input = Double.parseDouble(currentLine); } catch (final NumberFormatException ex) { System.out.println("That was not an double."); } System.out.println("\tDouble read: " + input); System.out.print("Input an double: "); }


Can you pass argument to procedures?

Yes. Procedures are otherwise known as functions, and functions can accept arguments.


Which header file should you include if you are to develop a function which can accept variable number of arguments?

stdarg.h


What does the phrase I bow to your will means?

I accept your command, or in other words, I will do as you say.


What is string class features in java?

String class is useful to accept inputs from commands prompt as string arguments


What is a basic internet request that lets you verify that a particular internet address exists and can accept request?

'ping' works on Windows, Mac and Linux:Open a console/command window and type for example "ping google.com" (without the quotes), and you get either a timeout or a message saying how long it took to get a response.


What function in c plus plus that only accept numbers?

All data is digital in a digital computer -- the numbers are merely an abstraction for real objects, even if those objects are non-numeric (such as people, animals, cars, etc). However, functions that accept actual numbers typically accept int, long, short or char arguments to represent whole numbers (integer values), float or double to represent real numbers (floating point values), or complex data types that are intrinsically numeric, such as std::complex objects.