How does JAVA accepts input from keyboard? -streams accepts input from keyboard. -stream is a flow of data. Types of stream: input stream : Receives the data. output stream : Writes the data. Note: System.out is used to print the output to the console. System.in is used to take input from the console. We can take input from the keyboard in two ways: using InputStreamReader class using Scanner class PROGRAM EXAMPLE: 1. Using InputStreamReader class import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class e_inputStream { public static void main(String args[]) throws IOException{ BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); // BufferedReader is used to read the data from the input stream System.out.println("Enter the number:"); int i=Integer.parseInt(br.readLine()); //converting the text to int ...
What is a variable ? A variable is like a container that holds a value. syntax: <data type> <variable name> = <value> eg: int i=10; where i is an integer that holds a value of 10. Scope of variable: Local Variable : its local which means its inside the method Instance Variable : its inside the class but outside the method. Class/Static Variable : its declared as static INSTANCE VARIABLE: declared inside the class but outside the method. visible to all methods. STATIC VARIABLE: declared with the static keyword in a class but outside the method. it is stored in static memory. LOCAL VARIABLE: declared inside the method. are accessible only during the method execution. Confused? let me show you an example with a program. public class scope{ int a=10; //<----instance variable static int c=20; //<----static variable public static void main(String args[]){ int x=30; //<----local var...