i am new to java
i am entering some data run time. like emp details
problem is char type
if i entered sex = m program will be terminated. exception is java.lang.Strin gIndexOutOfBoun dsException.
if i entered sex = male (enter key)
program executed successfully . but problem is i can't entered next command line arguments . program will display result empty values
This is my Program
i am entering some data run time. like emp details
problem is char type
if i entered sex = m program will be terminated. exception is java.lang.Strin gIndexOutOfBoun dsException.
if i entered sex = male (enter key)
program executed successfully . but problem is i can't entered next command line arguments . program will display result empty values
This is my Program
Code:
import java.io.*;
class str2
{
public static void main(String args[]) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter Employee ID = ");
int id = Integer.parseInt(br.readLine());
System.out.print("Enter Genger(M/F) : ");
char sex = (char)br.read();
br.readLine().charAt(0);
br.skip(2);
System.out.print("Enter Employee Name = ");
String name = br.readLine();
System.out.println("Employee Name = " + name);
System.out.println("Employee ID = " + id);
System.out.println("Employee Gender = " + sex);
}
}
Comment