write a program to imput name, age, and date of birth and displays using input method(streams and bufferr)
C program
pls answer(urgent)
Answers
Answer:
Hey buddy hope it helps
Explanation:
Try this !!!
package: java.lang
public final class System{
//class fields and methods
}
System.in refers InputStream object and corresponds to keyboard input or any input source specified by the host environment or user.
System.out refers OutputStream object and corresponds to display output(monitor) or any output destination specified by the host environment or user.
System.err refers error output stream object and corresponds to display error output(monitor) or anyoutput destination specified by the host environment or user.
HOW TO DISPLAY THE OUTPUT ONTO THE SCREEN?
We use print() and println() method of System.out to display the output.
System.out.print(“Hello”); //keeps the cursor on the same line after displaying output
System.out.println(“Hello”); //keeps the cursor on the next line after displaying output
HOW DATA IS ACCEPTED FROM KEYBOARD ?
We need three objects,
System.in
InputStreamReader
BufferedReader
InputStreamReader and BufferedReader are classes in java.io package.
The data is received in the form of bytes from the keyboard by System.in which is an InputStream object.
Then the InputStreamReader reads bytes and decodes them into characters.
Then finally BufferedReader object reads text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.
InputStreamReader inp = new InputStreamReader(system.in);
BufferedReader br = new BufferedReader(inp);
EXAMPLE PROGRAM:
C
import java.io.*;
public class InputOperationsExample
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter your name: ");
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
String name = br.readLine();
System.out.println("Your name is: "+name);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
import java.io.*;
public class InputOperationsExample
{
public static void main(String args[]) throws IOException
{
System.out.println("Enter your name: ");
InputStreamReader inp = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(inp);
String name = br.readLine();
System.out.println("Your name is: "+name);
}
}
Hope it helps and plzz mark as the brainliest !!
Explanation:
Following are the methods with the description that we have for the Java BufferedReader class.
Method Description
int read()
Reads a single character
String readLine()
It reads a line of text
void reset()
Repositions the stream to the position where the mark method was last called
int read(char[] cb, int off , int len)
Reads the characters in a portion of an array
boolean markSupported()
It tests the input stream support for reset and mark method
boolean ready()
It checks whether the input stream is ready for reading
long skip(long n)
skips the characters
void close()
It closes the input stream
void mark(int readAheadLimit)
Used to mark the current position in the stream