answersLogoWhite

0

JDK 5.0 provides a feature to read input from console. Java.util,Scanner is used for this purpose. This code read a String and an Integer from the console and stores them in the variables.import java.util.Scanner;

public class InputExp {

public static void main(String[] args) {

String name;

int age;

Scanner in = new Scanner(System.in);

// Reads a single line from the console

// and stores into name variable

name = in.nextLine();

// Reads a integer from the console

// and stores into age variable

age=in.nextInt();

in.close();

// Prints name and age to the console

System.out.println("Name :"+name);

System.out.println("Age :"+age);

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

How to print a symbol in Java using the ASCII value?

In order to print a character using its ASCII value, you need to first assign it to a char value like this: char c = (char) 65; In this example, we are casting the int 65 to a char, which converts it to an 'A', since 65 is the ASCII value for the capital letter 'a'. Next, you can print it out if you want: System.out.println(c); That's pretty much all there is to it!


How read xml file in java?

Java provides several XML Parsers like DOM, SAX or JDOM and API javax.xml.parsers by using those we can easily read xml files in Java. DOM is quickest and easiest way to read XMlL file in Java.


Can you specify variable field width in scanf format string?

AnswerYou can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value); The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.AnswerIf you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:printf("%*d", width, num);That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.


Header files in Java programming?

Java does not require header files like C/C++.


What does java and java fx do?

JAVA is Group Of Technologies Like Java SE, Java EE, Java ME and Java FX is a Latest Technology Released From SUN Micro Systems Sun Developed Java FX as Counterpart to Microsoft's Graphics Libraries and Rich Support of Visual Studio to GUI Classes of .NET Framework. But in JAVA FX We can Do some advanced Graphics Operations in Programming Apart From AWT & Swing of Java SE and Rich Internet Application Technologies Like Enterprise Java Beans (EJB),JSP Of Java EE.

Related Questions

What Do you Open your java File With?

.java files can be opened using an IDE (like Eclipse or NetBeans) or with notepad.exe.


How do you compile java servlet?

The Java Servlet is like every other Java class. You can compile it using the javac command or if you are using a Integrated Development Environment (IDE) like Eclipse, it will compile the class for you. One main difference w.r.t Servlets is the fact that, they get deployed into EAR files (Enterprise Archive Files) and not JAR files (Java Archive Files) like normal java apps.


How do you compile servlet in java using tomcat?

Tomcat is a server. It is used to deploy and run Servlets and not compile them. A Servlet is a java file and has to be compiled just like any other Java Class.


How to print a symbol in Java using the ASCII value?

In order to print a character using its ASCII value, you need to first assign it to a char value like this: char c = (char) 65; In this example, we are casting the int 65 to a char, which converts it to an 'A', since 65 is the ASCII value for the capital letter 'a'. Next, you can print it out if you want: System.out.println(c); That's pretty much all there is to it!


How do you write java programme using two mainmethods?

Use a text-editor like Notepad.


How read xml file in java?

Java provides several XML Parsers like DOM, SAX or JDOM and API javax.xml.parsers by using those we can easily read xml files in Java. DOM is quickest and easiest way to read XMlL file in Java.


How can I effectively measure the performance of my Java application using Java microbenchmarking techniques?

To effectively measure the performance of your Java application using Java microbenchmarking techniques, you can utilize tools like JMH (Java Microbenchmark Harness) to create and run microbenchmarks. These benchmarks can help you analyze the execution time and efficiency of specific code snippets or methods in your application. By carefully designing and running these microbenchmarks, you can gather valuable insights into the performance characteristics of your Java application and identify areas for optimization.


Coding?

Writing instructions for computers to execute, often using programming languages like Python, Java, or C++.


What is Control structures in java?

Control structures in java are nothing but like how u structure your program based on conditions like if-else using switch-case using for loops all together conditions applying things are called control structures


How a software or mobile apps development company organization structure should look like?

Using language like java c c++ and html


Can you specify variable field width in scanf format string?

AnswerYou can't specify a variable field with a fixed format string, but you can get around this by making the format string variable:int width; char format[20]; /* or whatever size is appropriate */ int value; ... sprintf(format, "%%%dd", width); /* generates a string like "%5d" */ scanf(format, &value); The only drawback to this method, other than requiring two statements, is that the compiler can't do a sanity check on the arguments to scanf like it can when the format is a string constant.AnswerIf you want to specify a variable width in a printf format string (as opposed to scanf), you can do the following:printf("%*d", width, num);That will use the value of "width" as the width for formatting the value of "num" as a decimal integer.


Why won't RuneScape load?

You may need to update your java, if that's not the case, try using a different browser altogether like Mozilla or Safari.