0% found this document useful (0 votes)
24 views

Object Oriented Programming

This document discusses 4 different input methods in Java: 1) the Scanner method which uses Scanner class to take input through System.in, 2) the Console class method which uses Console class to read input, 3) the JOptionPane method which uses a dialog box for input, and 4) the BufferedReader method which uses BufferedReader class to read input from InputStreamReader. Each method is demonstrated through a code example of how to implement it.

Uploaded by

ArduGeek
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Object Oriented Programming

This document discusses 4 different input methods in Java: 1) the Scanner method which uses Scanner class to take input through System.in, 2) the Console class method which uses Console class to read input, 3) the JOptionPane method which uses a dialog box for input, and 4) the BufferedReader method which uses BufferedReader class to read input from InputStreamReader. Each method is demonstrated through a code example of how to implement it.

Uploaded by

ArduGeek
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

DIFFERENT WAYS OF INPUT METHOD AND TECHNIQUES ON JAVA

1. Scanner Method

2. public String input1()


3. {
4.
System.out.println("enter the input");
5.
Scanner sc=new Scanner(System.in);
6.
String s1=sc.nextLine();
7.
return s1;
8. }

2.

Console Class Method

public String input2()throws IOError


{

3.
{

Console c=System.console();
String s2=null;
s2=c.readLine("enter the value");
return s2;

JOption Method
public String input3()
System.out.println("enter the input");
String s3=javax.swing.JOptionPane.showInputDialog("enter the text");
return s3;

4. BufferedReader Method
public String input4()throws Exception
{
System.out.println("enter the input");
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String s4=br.readLine();
return s4;
}

You might also like