Methods: String Next
Methods: String Next
Methods: String Next
The java.util.Scanner class is a simple text scanner which can parse primitive types and strings using regular
expressions.Following are the important points about Scanner:
A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace.
A scanning operation may block waiting for input.
Methods
String next()
This method finds and returns the next complete token from this scanner.
String next(String pattern)
This method returns the next token if it matches the pattern constructed from the
specified string
boolean nextBoolean()
This method scans the next token of the input into a boolean value and returns that
value.
byte nextByte()
This method scans the next token of the input as a byte
float nextFloat()
This method scans the next token of the input as a float.
int nextInt()
This method scans the next token of the input as an int.
String nextLine()
This method advances this scanner past the current line and returns the input that was
skipped.
long nextLong()
This method scans the next token of the input as a long.
short nextShort()
This method scans the next token of the input as a short.
Example:
import java . util . Scanner ;
public class intro
{
public static void main ( String args []) {
String name ;
int age ;
Scanner s = new Scanner ( System . in );
System . out . println (" Enter your name ");
name = s . next ();
System . out . println (" Enter your age ");
age = s. nextInt ();
s.close();
System . out . println (" Name : " + name );
System . out . println (" Age : " + age );
}
}
Pen Stand
EcoPencil
UnitPrice(Rs.)
560
100
Qty
2
5
1120
500
Total
: Rs.
Received
: Rs.
1620
2000
Balance returned
Rs.
380