Computer Science, asked by srinidhitr2005, 8 months ago

How to input a string and a integer in java Please give me the syntax

Answers

Answered by bakanmanibalamudha
2

Explanation:

In this tutorial we are gonna see how to accept input from user. We are using Scanner class to get the input. In the below example we are getting input String, integer and a float number. For this we are using following methods:

1) public String nextLine(): For getting input String

2) public int nextInt(): For integer input

3) public float nextFloat(): For float input

Answered by Anonymous
0

Answer:

Here's one way to do this:

  • Get a String of characters that is in an integer format, e.g., "123". String input = scanner. nextLine(); // from console input example above.
  • Use the Integer class to parse the string of characters into an integer. int number = Integer.parseInt( input ); // converts a String into an int value.

Steps:

  • The user enters an integer value when asked.
  • This value is taken from the user with the help of nextInt() method of Scanner Class. The nextInt() method, in Java, reads the next integer value from the console into the specified variable.

Syntax:

Explanation:

class AssignmentOperator {

public static void main(String[] args) {

System.out.println("Java programming is interesting.");

}

}

Similar questions