SlideShare a Scribd company logo
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?");
}
}
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): ");
}
}
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);
}
}
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();
}
}

More Related Content

What's hot (19)

PPTX
Java Generics
Zülfikar Karakaya
 
PDF
Java programming lab manual
sameer farooq
 
PDF
Java practical(baca sem v)
mehul patel
 
PPT
Java Generics for Dummies
knutmork
 
DOCX
Java PRACTICAL file
RACHIT_GUPTA
 
PPTX
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
DOC
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
PDF
FP in Java - Project Lambda and beyond
Mario Fusco
 
PPS
Class method
kamal kotecha
 
PDF
Java_practical_handbook
Manusha Dilan
 
DOCX
Java programming lab_manual_by_rohit_jaiswar
ROHIT JAISWAR
 
PPTX
Java Programs
vvpadhu
 
PDF
Java Generics - by Example
Ganesh Samarthyam
 
PPTX
16. Java stacks and queues
Intro C# Book
 
PDF
Important java programs(collection+file)
Alok Kumar
 
PPTX
07. Arrays
Intro C# Book
 
PDF
Java Lab Manual
Naveen Sagayaselvaraj
 
PDF
Kotlin, why?
Paweł Byszewski
 
PPTX
Scala - where objects and functions meet
Mario Fusco
 
Java Generics
Zülfikar Karakaya
 
Java programming lab manual
sameer farooq
 
Java practical(baca sem v)
mehul patel
 
Java Generics for Dummies
knutmork
 
Java PRACTICAL file
RACHIT_GUPTA
 
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
CS2309 JAVA LAB MANUAL
Lavanya Arunachalam A
 
FP in Java - Project Lambda and beyond
Mario Fusco
 
Class method
kamal kotecha
 
Java_practical_handbook
Manusha Dilan
 
Java programming lab_manual_by_rohit_jaiswar
ROHIT JAISWAR
 
Java Programs
vvpadhu
 
Java Generics - by Example
Ganesh Samarthyam
 
16. Java stacks and queues
Intro C# Book
 
Important java programs(collection+file)
Alok Kumar
 
07. Arrays
Intro C# Book
 
Java Lab Manual
Naveen Sagayaselvaraj
 
Kotlin, why?
Paweł Byszewski
 
Scala - where objects and functions meet
Mario Fusco
 

Viewers also liked (14)

PPTX
Java: Collections
Arthur Emanuel
 
ODP
Preparing Java 7 Certifications
Giacomo Veneri
 
DOC
Advance java practicalty bscit sem5
ashish singh
 
PPT
java collections
javeed_mhd
 
PPTX
Java collections
Amar Kutwal
 
PDF
Java Collections Tutorials
Prof. Erwin Globio
 
PPTX
Introduction to Java Programming
One97 Communications Limited
 
PPT
Ch01 basic-java-programs
James Brotsos
 
PDF
Java Certification by HUJAK - 2015-05-12 - at JavaCro'15 conference
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
PPT
Most Asked Java Interview Question and Answer
TOPS Technologies
 
PDF
Java Collections Framework
guestd8c458
 
PDF
Advanced Java Practical File
Soumya Behera
 
PPT
Introduction to-programming
BG Java EE Course
 
DOCX
Java codes
Hussain Sherwani
 
Java: Collections
Arthur Emanuel
 
Preparing Java 7 Certifications
Giacomo Veneri
 
Advance java practicalty bscit sem5
ashish singh
 
java collections
javeed_mhd
 
Java collections
Amar Kutwal
 
Java Collections Tutorials
Prof. Erwin Globio
 
Introduction to Java Programming
One97 Communications Limited
 
Ch01 basic-java-programs
James Brotsos
 
Java Certification by HUJAK - 2015-05-12 - at JavaCro'15 conference
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Most Asked Java Interview Question and Answer
TOPS Technologies
 
Java Collections Framework
guestd8c458
 
Advanced Java Practical File
Soumya Behera
 
Introduction to-programming
BG Java EE Course
 
Java codes
Hussain Sherwani
 
Ad

Similar to Java simple programs (12)

PDF
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
PDF
Java Fundamentals
Shalabh Chaudhary
 
DOCX
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
PPT
Command line arguments.21
myrajendra
 
PPTX
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
SrinivasGopalan2
 
PDF
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
PPTX
study of java
Prashant Mishra
 
PPTX
Getting Program Input
Dr. Rosemarie Sibbaluca-Guirre
 
PPTX
Java Programming Tutorials Basic to Advanced 2
JALALUDHEENVK1
 
PPTX
java: basics, user input, data type, constructor
Shivam Singhal
 
PPTX
Reading and writting v2
ASU Online
 
PPTX
Reading and writting
andreeamolnar
 
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Java Fundamentals
Shalabh Chaudhary
 
Class notes(week 5) on command line arguments
Kuntal Bhowmick
 
Command line arguments.21
myrajendra
 
JAVA_SAMPLE CODING, JAVA BASICS PROGRAMS.pptx
SrinivasGopalan2
 
Command line-arguments-in-java-tutorial
Kuntal Bhowmick
 
study of java
Prashant Mishra
 
Getting Program Input
Dr. Rosemarie Sibbaluca-Guirre
 
Java Programming Tutorials Basic to Advanced 2
JALALUDHEENVK1
 
java: basics, user input, data type, constructor
Shivam Singhal
 
Reading and writting v2
ASU Online
 
Reading and writting
andreeamolnar
 
Ad

Recently uploaded (20)

PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Pyhton with Mysql to perform CRUD operations.pptx
Ramakrishna Reddy Bijjam
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
SPINA BIFIDA: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
People & Earth's Ecosystem -Lesson 2: People & Population
marvinnbustamante1
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
Dimensions of Societal Planning in Commonism
StefanMz
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 

Java simple programs

  • 1. 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?"); } }
  • 2. 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): "); } }
  • 3. 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); } }
  • 4. 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(); } }