Embed presentation
Download to read offline
![Command Line Argument in JAVA
public class UseArgument
{
public static void main(String[] args)
{
System.out.print("Hi");
System.out.print(args[0]);
System.out.println("How are you?");
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-1-2048.jpg)
![swap two numbers using only two variables in Java
import java.io.*;
class swap
{
public static void main(String[]args) throws IOException
{
int a,b;
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter the 1st no.(a): ");
a=Integer.parseInt(din.readLine());
System.out.println("Enter the 2nd no.(b): ");
b=Integer.parseInt(din.readLine());
a=a+b;
b=a-b;
a=a-b;
System.out.println("The swaping no. is ");
System.out.println("Enter the 1st no.(a): ");
System.out.println("Enter the 2nd no.(b): ");
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-2-2048.jpg)
![Reading data from keyboard by
InputStreamReader and BufferdReader class:
import java.io.*;
class G5{
public static void main(String args[])throws Exception
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
System.out.println("Enter your name");
String name=br.readLine();
System.out.println("Welcome "+name);
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-3-2048.jpg)
![Java Scanner Example to get input from console
import java.util.Scanner;
class ScannerTest{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter your rollno");
int rollno=sc.nextInt();
System.out.println("Enter your name");
String name=sc.next();
System.out.println("Enter your fee");
double fee=sc.nextDouble();
System.out.println("Rollno:"+rollno+" name:"+name+" fe
e:"+fee);
sc.close();
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-4-2048.jpg)

The document contains 4 code snippets demonstrating different ways to take input in Java programs: 1) Using command line arguments and the args array to print a greeting with a passed in name 2) Swapping two integers entered from the keyboard using only two variables 3) Reading input from the keyboard using InputStreamReader and BufferedReader classes 4) Taking input using the Scanner class to read an integer, string, and double from console input
![Command Line Argument in JAVA
public class UseArgument
{
public static void main(String[] args)
{
System.out.print("Hi");
System.out.print(args[0]);
System.out.println("How are you?");
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-1-2048.jpg)
![swap two numbers using only two variables in Java
import java.io.*;
class swap
{
public static void main(String[]args) throws IOException
{
int a,b;
DataInputStream din=new DataInputStream(System.in);
System.out.println("Enter the 1st no.(a): ");
a=Integer.parseInt(din.readLine());
System.out.println("Enter the 2nd no.(b): ");
b=Integer.parseInt(din.readLine());
a=a+b;
b=a-b;
a=a-b;
System.out.println("The swaping no. is ");
System.out.println("Enter the 1st no.(a): ");
System.out.println("Enter the 2nd no.(b): ");
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-2-2048.jpg)
![Reading data from keyboard by
InputStreamReader and BufferdReader class:
import java.io.*;
class G5{
public static void main(String args[])throws Exception
{
InputStreamReader r=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(r);
System.out.println("Enter your name");
String name=br.readLine();
System.out.println("Welcome "+name);
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-3-2048.jpg)
![Java Scanner Example to get input from console
import java.util.Scanner;
class ScannerTest{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter your rollno");
int rollno=sc.nextInt();
System.out.println("Enter your name");
String name=sc.next();
System.out.println("Enter your fee");
double fee=sc.nextDouble();
System.out.println("Rollno:"+rollno+" name:"+name+" fe
e:"+fee);
sc.close();
}
}](https://image.slidesharecdn.com/javasimpleprograms-150805154714-lva1-app6892/75/Java-simple-programs-4-2048.jpg)