SlideShare a Scribd company logo
Java Program for Addition of two
numbers
importjava.io.*;
importjava.lang.*;
classAddition
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("enter second number: ");
n2=Integer.parseInt(br.readLine());
n1+=n2;
System.out.println("addition of two numbers is: "+n1);
}
}
Java Program for Subtraction of two
numbers
importjava.io.*;
importjava.lang.*;
classSub
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number: ");
n2=Integer.parseInt(br.readLine());
n1-=n2;
System.out.println("Subtraction of two given numbers is: "+n1);
}
}
Java Program for Multiplication of two
numbers
importjava.io.*;
importjava.lang.*;
classMul
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number ");
n2=Integer.parseInt(br.readLine());
n1*=n2; // or n1=n1*n2
System.out.println("Multiplication of two numbers is: "+n1);
}
}
Binary To Decimal Conversion
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
publicclassBinaryToDecimal
{
publicstaticvoidmain(String args[]) throwsException, IOException
{
intbin;
inti = 0;
intldigit=0;
intdcm=0;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.print("Enter Binary value: ");
bin=Integer.parseInt(br.readLine());
while(bin != 0)
{
ldigit = bin%10; //last digit of binary no
dcm = dcm+ldigit *((int) Math.pow(2,i));
i++;
bin = bin / 10; //removimg last digit from binary no
}
System.out.println("The decimal value for the given binary is:
"+dcm);
}
}
Solving Power Series
importjava.io.*;
classSeries2
{
publicstaticvoidmain(String args[]) throwsIOException
{
intn;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter n value: ");
n = Integer.parseInt(br.readLine());
if(n>0)
{
floatsum=0;
for(inti=1; i<=n; i++)
sum=sum+(float)(1)/(i*i);
System.out.println("Sum of Series:"+sum);
}
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Find Frequency
Count of a Word in Given Text
importjava.io.*;
classFrequencyCount
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the String: ");
String s=br.readLine();
System.out.println("Enter substring: ");
String sub=br.readLine();
intind,count=0;
for(inti=0; i+sub.length()<=s.length(); i++) //i+sub.length() is
used to reduce comparisions
{
ind=s.indexOf(sub,i);
if(ind>=0)
{
count++;
i=ind;
ind=-1;
}
}
System.out.println("Occurence of '"+sub+"' in String is "+count);
}
}
Java Program to Check Given String
is a POLYNDROME or Not
importjava.io.*;
importjava.lang.*;
classPolyndrome
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the String: ");
String s=br.readLine();
String temp=s;
StringBuffersb= newStringBuffer(s);
sb.reverse();
s=sb.toString();
if(s.equals(temp))
System.out.print("String is polyndrome");
else
System.out.println("String is not polyndrome");
}
}
Java Program to Find Factorial of a
Given Number Using Recursion
importjava.io.*;
classFactorial
{
intfact(intn)
{
if(n<=1)
return1;
else
returnn*fact(n-1);
}
}
classRecursionFact
{
publicstaticvoidmain(String args[]) throwsIOException
{
intno;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter a Number: ");
no = Integer.parseInt(br.readLine());
if(no<0)
{
System.out.println("Negative number is not acceptable.");
}
else
{
Factorial f=newFactorial();
System.out.println("Factorial of "+no+" is: "+f.fact(no));
}
}
}
Java Program to Print Series
1,2,9,28,65
importjava.io.*;
classSeries
{
publicstaticvoidmain(String args[]) throwsIOException
{
intn;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter no.of elements in series: ");
n = Integer.parseInt(br.readLine());
if(n>0)
{
System.out.println("Series:");
for(inti=0; i<n; i++)
{
System.out.println("t"+(int)(Math.pow(i,3)+1)); //Pattern
for elements
}
}
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Print Prime Numbers
With Less Comparisons
importjava.io.*;
importjava.lang.*;
classPrime
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the value: ");
intn=Integer.parseInt(br.readLine());
System.out.println("Prime numbers are: ");
for(inti=1; i<=n; i++)
{
intnf=0;
for(intj=1; j<=(i/2); j++) //( i/2) reduces no.ofcomparisions
{
if(i%j==0)
nf++;
}
if(nf==1)
System.out.print(" "+i);
}
}
}
Java Program to Find Roots of a
Quadratic Equation
importjava.io.*;
classQuad
{
publicstaticvoidmain(String args[]) throwsIOException
{
inta,b,c;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter a,b,c values: ");
a= Integer.parseInt(br.readLine());
b= Integer.parseInt(br.readLine());
c= Integer.parseInt(br.readLine());
if((a==0)&&(b==0)&&(c==0))
{
System.out.println("Enter atleast two non-zero co-efficients");
}
else
{
floatr1=0,r2=0;
if(a==0)
{
r1= (float)-c/b;
System.out.println("The roots are:"+r1);
}
else
{
floatd=(b*b)-(4*a*c);
if(d<0)
{
System.out.println("Roots are imaginary");
floatreal=(float)(-b)/(2*a);
floatimg=(float)(Math.sqrt(Math.abs(d)))/(2*a);
System.out.println("r1="+real+"+i"+img);
System.out.println("r2="+real+"-i"+img);
}
else
{
r1=(float)(-b+Math.sqrt(d))/(2*a);
r2=(float)(-b-Math.sqrt(d))/(2*a);
if(d==0)
{
System.out.println("Roots are real and equal");
}
else
{
System.out.println("Roots are real and different");
}
System.out.println("r1="+r1);
System.out.println("r2="+r2);
}
}
}
}
}
Java Program to Print Square Series
0,1,4,9,16
importjava.io.*;
classSquareSeries
{
publicstaticvoidmain(String args[]) throwsIOException
{
intn;
BufferedReaderbr =
newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter no.of elements in series: ");
n = Integer.parseInt(br.readLine());
if(n>0)
{
System.out.println("Series:");
for(inti=0; i<(n-1); i++)
{
System.out.println("t"+(int)(Math.pow(i,2)));
}
}
else
System.out.println("You Entered the Wrong no.");
}
}
Java Program to Find Given Number
Is Even or Odd
importjava.io.*;
importjava.lang.*;
classEvenOdd
{
publicstaticvoidmain(String args[])throwsIOException
{
intn=0;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter number: ");
n=Integer.parseInt(br.readLine());
n=n%2;
if(n==0)
System.out.println("The given number is even ");
else
System.out.println("The given number is odd ");
}
}
Java Program for Multiplication of two
numbers
importjava.io.*;
importjava.lang.*;
classMul
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number ");
n2=Integer.parseInt(br.readLine());
n1*=n2; // or n1=n1*n2
System.out.println("Multiplication of two numbers is: "+n1);
}
}
Java Program for Division of Two
Numbers
importjava.io.*;
importjava.lang.*;
classDiv
{
publicstaticvoidmain(String args[])throwsIOException
{
intn1=0,n2;
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter first number: ");
n1=Integer.parseInt(br.readLine());
System.out.println("Enter second number: ");
n2=Integer.parseInt(br.readLine());
n1/=n2;
System.out.println("Division of two numbers is: "+n1);
}
}
Java Program for Addition of Two
Static Integer Numbers
importjava.io.*;
importjava.lang.*;
classStaticAdd
{
publicstaticvoidmain(String args[])
{
intn1=10,n2=20; //Static Defining of two Integer Variables
n1+=n2; // Performing Addition
System.out.println("Addition: "+n1);
}
}
Java Program for Multiplication of
Two Static Numbers
importjava.io.*;
importjava.lang.*;
classStaticMul
{
publicstaticvoidmain(String args[])
{
intn1=20,n2=10; //Defining Static Integer values
n1*=n2; // or n1=n1*n2;
System.out.println("Multiplicatation : "+n1);
}
}
Java Program to find Given Number is
Prime or Not
/* Write a Java program to Find whether number is Prime or Not. */
classPrimeNumber
{
publicstaticvoidmain(String args[])
{
intnumber = Integer.parseInt(args[0]);
intflag=0;
for(inti=2; i<number; i++)
{
if(number%i==0)
{
System.out.println(number+" is not a Prime Number");
flag = 1;
break;
}
}
if(flag==0)
System.out.println(number+" is a Prime Number");
}
}
Java Program to Find Whether Given
number is Armstrong or not
/*Write a program to find whether given no. is Armstrong or not.
Example :
Input - 153
Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
classArmstrong
{
publicstaticvoidmain(String args[])
{<br> //Read Command Line Argument
intnum = Integer.parseInt(args[0]);
intn = num; //use to compare at If stmt
intcheck=0,remainder;
while(num> 0)
{
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
}
Java Program to Find Factorial of a
Given Number using While Loop
importjava.io.*;
importjava.lang.*;
classFactorial
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter Number: ");
intnum=Integer.parseInt(br.readLine());
intresult = 1;
while(num>0)
{
result = result * num;
num--;
}
System.out.println("Factorial of Given Number is : "+result);
}
}
Java Program to Find Maximum of
Two Numbers
classMaxoftwo
{
publicstaticvoidmain(String args[])
{
//taking value as command line argument.
//Converting String format to Integer value
inti = Integer.parseInt(args[0]);
intj = Integer.parseInt(args[1]);
if(i> j)
System.out.println(i+" is greater than "+j);
else
System.out.println(j+" is greater than "+i);
}
}
Java Program to Print Prime Numbers
up to Given Number
importjava.io.*;
importjava.lang.*;
classPrime
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the value: ");
intn=Integer.parseInt(br.readLine());
System.out.println("Prime numbers are: ");
for(inti=1;i<=n;i++)
{
intp=0;
for(intj=1;j<=i;j++)
{
if(i%j==0)
p++;
}
if(p==2)
System.out.print(" "+i);
}
}
}
Java Program for Fibonacci Series
importjava.io.*;
importjava.lang.*;
classFibonacci
{
publicstaticvoidmain(String args[]) throwsIOException
{
BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
System.out.println("Enter the value:");
intn=Integer.parseInt(br.readLine());
intt1=0,t2=1;
System.out.print("Fibonacci Series is "+t1+" "+t2);
for(inti=0; i<n; i++)
{
intt3=t1+t2;
t1=t2;
t2=t3;
System.out.print(" "+t3);
}
}
}

More Related Content

What's hot

Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
Mukesh Tekwani
 
Java programs
Java programsJava programs
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
mustkeem khan
 
Java lab 2
Java lab 2Java lab 2
C# console programms
C# console programmsC# console programms
C# console programms
Yasir Khan
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
walia Shaan
 
Java Programs
Java ProgramsJava Programs
Java Programs
vvpadhu
 
Hoisting Nested Functions
Hoisting Nested Functions Hoisting Nested Functions
Hoisting Nested Functions
Feras Tanan
 
Hoisting Nested Functions
Hoisting Nested FunctionsHoisting Nested Functions
Hoisting Nested Functions
Feras Tanan
 
Java codes
Java codesJava codes
Java codes
Hussain Sherwani
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
Intel® Software
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
mustkeem khan
 
Class method
Class methodClass method
Class method
kamal kotecha
 
Isc computer project final upload last
Isc computer project final upload lastIsc computer project final upload last
Isc computer project final upload last
Arunav Ray
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 

What's hot (19)

C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
Java programs
Java programsJava programs
Java programs
 
Pattern printing programs
Pattern printing programsPattern printing programs
Pattern printing programs
 
Java programs
Java programsJava programs
Java programs
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Java Practical File Diploma
Java Practical File DiplomaJava Practical File Diploma
Java Practical File Diploma
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
 
C# console programms
C# console programmsC# console programms
C# console programms
 
Presentation1 computer shaan
Presentation1 computer shaanPresentation1 computer shaan
Presentation1 computer shaan
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Hoisting Nested Functions
Hoisting Nested Functions Hoisting Nested Functions
Hoisting Nested Functions
 
Hoisting Nested Functions
Hoisting Nested FunctionsHoisting Nested Functions
Hoisting Nested Functions
 
Java codes
Java codesJava codes
Java codes
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
Class method
Class methodClass method
Class method
 
Isc computer project final upload last
Isc computer project final upload lastIsc computer project final upload last
Isc computer project final upload last
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 

Viewers also liked

Fulieb Información para auspicios
Fulieb Información para auspiciosFulieb Información para auspicios
Fulieb Información para auspicios
generaknow
 
M Santosh GIS Engineer
M Santosh GIS EngineerM Santosh GIS Engineer
M Santosh GIS Engineersantoshmgis
 
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
generaknow
 
Preliminary Slide
Preliminary SlidePreliminary Slide
Preliminary Slidematty002
 
Storyboard for film
Storyboard for filmStoryboard for film
Storyboard for film
chloe spencer
 
ASO: Optimiser le référencement de votre application sur les stores d’applica...
ASO: Optimiser le référencement de votre application sur les stores d’applica...ASO: Optimiser le référencement de votre application sur les stores d’applica...
ASO: Optimiser le référencement de votre application sur les stores d’applica...
SwissPay.ch SA (We're hiring)
 
Transferencia de-calor
Transferencia de-calorTransferencia de-calor
Transferencia de-calor
Marielita Pedro Ochoa
 
Merchandising Museale - short guide
Merchandising Museale - short guideMerchandising Museale - short guide
Merchandising Museale - short guide
Luciano Gianni
 
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...Jeffrey Scott
 
10 judul penelitian komunikasi beserta konsep penelitian
10 judul penelitian komunikasi beserta konsep penelitian10 judul penelitian komunikasi beserta konsep penelitian
10 judul penelitian komunikasi beserta konsep penelitian
pycnat
 
Lucy winter 2015 resume 1203
Lucy winter 2015 resume 1203Lucy winter 2015 resume 1203
Lucy winter 2015 resume 1203
Lucy Winter
 

Viewers also liked (13)

Fulieb Información para auspicios
Fulieb Información para auspiciosFulieb Información para auspicios
Fulieb Información para auspicios
 
JResume2015
JResume2015JResume2015
JResume2015
 
M Santosh GIS Engineer
M Santosh GIS EngineerM Santosh GIS Engineer
M Santosh GIS Engineer
 
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
Memoria del I encuentro de Emprendedores e Inversores "Open Bolivia"
 
Preliminary Slide
Preliminary SlidePreliminary Slide
Preliminary Slide
 
Water
WaterWater
Water
 
Storyboard for film
Storyboard for filmStoryboard for film
Storyboard for film
 
ASO: Optimiser le référencement de votre application sur les stores d’applica...
ASO: Optimiser le référencement de votre application sur les stores d’applica...ASO: Optimiser le référencement de votre application sur les stores d’applica...
ASO: Optimiser le référencement de votre application sur les stores d’applica...
 
Transferencia de-calor
Transferencia de-calorTransferencia de-calor
Transferencia de-calor
 
Merchandising Museale - short guide
Merchandising Museale - short guideMerchandising Museale - short guide
Merchandising Museale - short guide
 
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...
Fluorescence spectroscopy as a monitoring technique for a MBR water reclamati...
 
10 judul penelitian komunikasi beserta konsep penelitian
10 judul penelitian komunikasi beserta konsep penelitian10 judul penelitian komunikasi beserta konsep penelitian
10 judul penelitian komunikasi beserta konsep penelitian
 
Lucy winter 2015 resume 1203
Lucy winter 2015 resume 1203Lucy winter 2015 resume 1203
Lucy winter 2015 resume 1203
 

Similar to Programs of java

Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
AnjaliSoorej
 
Oot practical
Oot practicalOot practical
Oot practical
Vipin Rawat @ daya
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
anupamfootwear
 
Java Programs
Java ProgramsJava Programs
Java Programs
AnjaliSoorej
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdf
hadpadrrajeshh
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
optokunal1
 
LAB1.docx
LAB1.docxLAB1.docx
LAB1.docx
Aditya Aggarwal
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
MaruMengesha
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
Ankit Gupta
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
ADITYA BHARTI
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
rajat630669
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
rajat630669
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
KimVeeL
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
deepakangel
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
MaruMengesha
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
Ankitchhabra28
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programsAbhishek Jena
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
davinci54
 

Similar to Programs of java (20)

Anjalisoorej imca133 assignment
Anjalisoorej imca133 assignmentAnjalisoorej imca133 assignment
Anjalisoorej imca133 assignment
 
Oot practical
Oot practicalOot practical
Oot practical
 
Codeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdfCodeimport java.util.Random; import java.util.Scanner;public .pdf
Codeimport java.util.Random; import java.util.Scanner;public .pdf
 
Java Programs
Java ProgramsJava Programs
Java Programs
 
Write a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdfWrite a Java application that asks for an integer and returns its fac.pdf
Write a Java application that asks for an integer and returns its fac.pdf
 
import java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdfimport java.util.;public class Program{public static void.pdf
import java.util.;public class Program{public static void.pdf
 
LAB1.docx
LAB1.docxLAB1.docx
LAB1.docx
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_17-Feb-2021_L8-...
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
The sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdfThe sample program for above series in JAVA will be like belowimpo.pdf
The sample program for above series in JAVA will be like belowimpo.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdfFactors.javaimport java.io.; import java.util.Scanner; class .pdf
Factors.javaimport java.io.; import java.util.Scanner; class .pdf
 
54240326 (1)
54240326 (1)54240326 (1)
54240326 (1)
 
54240326 copy
54240326   copy54240326   copy
54240326 copy
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs81818088 isc-class-xii-computer-science-project-java-programs
81818088 isc-class-xii-computer-science-project-java-programs
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 

Recently uploaded

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Programs of java

  • 1. Java Program for Addition of two numbers importjava.io.*; importjava.lang.*; classAddition { publicstaticvoidmain(String args[])throwsIOException { intn1,n2; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("enter first number: "); n1=Integer.parseInt(br.readLine()); System.out.println("enter second number: "); n2=Integer.parseInt(br.readLine()); n1+=n2; System.out.println("addition of two numbers is: "+n1); } } Java Program for Subtraction of two numbers importjava.io.*; importjava.lang.*; classSub { publicstaticvoidmain(String args[])throwsIOException { intn1,n2; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter first number: "); n1=Integer.parseInt(br.readLine()); System.out.println("Enter second number: "); n2=Integer.parseInt(br.readLine()); n1-=n2; System.out.println("Subtraction of two given numbers is: "+n1); } }
  • 2. Java Program for Multiplication of two numbers importjava.io.*; importjava.lang.*; classMul { publicstaticvoidmain(String args[])throwsIOException { intn1=0,n2; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter first number "); n1=Integer.parseInt(br.readLine()); System.out.println("Enter second number "); n2=Integer.parseInt(br.readLine()); n1*=n2; // or n1=n1*n2 System.out.println("Multiplication of two numbers is: "+n1); } }
  • 3. Binary To Decimal Conversion importjava.io.BufferedReader; importjava.io.IOException; importjava.io.InputStreamReader; publicclassBinaryToDecimal { publicstaticvoidmain(String args[]) throwsException, IOException { intbin; inti = 0; intldigit=0; intdcm=0; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.print("Enter Binary value: "); bin=Integer.parseInt(br.readLine()); while(bin != 0) { ldigit = bin%10; //last digit of binary no dcm = dcm+ldigit *((int) Math.pow(2,i)); i++; bin = bin / 10; //removimg last digit from binary no } System.out.println("The decimal value for the given binary is: "+dcm); } } Solving Power Series importjava.io.*; classSeries2 { publicstaticvoidmain(String args[]) throwsIOException { intn; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter n value: "); n = Integer.parseInt(br.readLine()); if(n>0) { floatsum=0; for(inti=1; i<=n; i++) sum=sum+(float)(1)/(i*i); System.out.println("Sum of Series:"+sum);
  • 4. } else System.out.println("You Entered the Wrong no."); } } Java Program to Find Frequency Count of a Word in Given Text importjava.io.*; classFrequencyCount { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter the String: "); String s=br.readLine(); System.out.println("Enter substring: "); String sub=br.readLine(); intind,count=0; for(inti=0; i+sub.length()<=s.length(); i++) //i+sub.length() is used to reduce comparisions { ind=s.indexOf(sub,i); if(ind>=0) { count++; i=ind; ind=-1; } } System.out.println("Occurence of '"+sub+"' in String is "+count); } } Java Program to Check Given String is a POLYNDROME or Not
  • 5. importjava.io.*; importjava.lang.*; classPolyndrome { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter the String: "); String s=br.readLine(); String temp=s; StringBuffersb= newStringBuffer(s); sb.reverse(); s=sb.toString(); if(s.equals(temp)) System.out.print("String is polyndrome"); else System.out.println("String is not polyndrome"); } } Java Program to Find Factorial of a Given Number Using Recursion importjava.io.*; classFactorial { intfact(intn) { if(n<=1) return1; else returnn*fact(n-1); } } classRecursionFact { publicstaticvoidmain(String args[]) throwsIOException { intno; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter a Number: "); no = Integer.parseInt(br.readLine()); if(no<0) {
  • 6. System.out.println("Negative number is not acceptable."); } else { Factorial f=newFactorial(); System.out.println("Factorial of "+no+" is: "+f.fact(no)); } } } Java Program to Print Series 1,2,9,28,65 importjava.io.*; classSeries { publicstaticvoidmain(String args[]) throwsIOException { intn; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter no.of elements in series: "); n = Integer.parseInt(br.readLine()); if(n>0) { System.out.println("Series:"); for(inti=0; i<n; i++) { System.out.println("t"+(int)(Math.pow(i,3)+1)); //Pattern for elements } } else System.out.println("You Entered the Wrong no."); } } Java Program to Print Prime Numbers With Less Comparisons importjava.io.*;
  • 7. importjava.lang.*; classPrime { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter the value: "); intn=Integer.parseInt(br.readLine()); System.out.println("Prime numbers are: "); for(inti=1; i<=n; i++) { intnf=0; for(intj=1; j<=(i/2); j++) //( i/2) reduces no.ofcomparisions { if(i%j==0) nf++; } if(nf==1) System.out.print(" "+i); } } } Java Program to Find Roots of a Quadratic Equation importjava.io.*; classQuad { publicstaticvoidmain(String args[]) throwsIOException { inta,b,c; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter a,b,c values: "); a= Integer.parseInt(br.readLine()); b= Integer.parseInt(br.readLine()); c= Integer.parseInt(br.readLine()); if((a==0)&&(b==0)&&(c==0)) { System.out.println("Enter atleast two non-zero co-efficients"); } else { floatr1=0,r2=0; if(a==0) { r1= (float)-c/b; System.out.println("The roots are:"+r1); } else
  • 8. { floatd=(b*b)-(4*a*c); if(d<0) { System.out.println("Roots are imaginary"); floatreal=(float)(-b)/(2*a); floatimg=(float)(Math.sqrt(Math.abs(d)))/(2*a); System.out.println("r1="+real+"+i"+img); System.out.println("r2="+real+"-i"+img); } else { r1=(float)(-b+Math.sqrt(d))/(2*a); r2=(float)(-b-Math.sqrt(d))/(2*a); if(d==0) { System.out.println("Roots are real and equal"); } else { System.out.println("Roots are real and different"); } System.out.println("r1="+r1); System.out.println("r2="+r2); } } } } } Java Program to Print Square Series 0,1,4,9,16 importjava.io.*; classSquareSeries { publicstaticvoidmain(String args[]) throwsIOException { intn; BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter no.of elements in series: "); n = Integer.parseInt(br.readLine()); if(n>0) { System.out.println("Series:"); for(inti=0; i<(n-1); i++) {
  • 9. System.out.println("t"+(int)(Math.pow(i,2))); } } else System.out.println("You Entered the Wrong no."); } } Java Program to Find Given Number Is Even or Odd importjava.io.*; importjava.lang.*; classEvenOdd { publicstaticvoidmain(String args[])throwsIOException { intn=0; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter number: "); n=Integer.parseInt(br.readLine()); n=n%2; if(n==0) System.out.println("The given number is even "); else System.out.println("The given number is odd "); } } Java Program for Multiplication of two numbers importjava.io.*; importjava.lang.*; classMul { publicstaticvoidmain(String args[])throwsIOException { intn1=0,n2; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter first number "); n1=Integer.parseInt(br.readLine()); System.out.println("Enter second number "); n2=Integer.parseInt(br.readLine()); n1*=n2; // or n1=n1*n2
  • 10. System.out.println("Multiplication of two numbers is: "+n1); } } Java Program for Division of Two Numbers importjava.io.*; importjava.lang.*; classDiv { publicstaticvoidmain(String args[])throwsIOException { intn1=0,n2; BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter first number: "); n1=Integer.parseInt(br.readLine()); System.out.println("Enter second number: "); n2=Integer.parseInt(br.readLine()); n1/=n2; System.out.println("Division of two numbers is: "+n1); } } Java Program for Addition of Two Static Integer Numbers importjava.io.*; importjava.lang.*; classStaticAdd { publicstaticvoidmain(String args[]) { intn1=10,n2=20; //Static Defining of two Integer Variables n1+=n2; // Performing Addition System.out.println("Addition: "+n1); } } Java Program for Multiplication of Two Static Numbers importjava.io.*; importjava.lang.*; classStaticMul
  • 11. { publicstaticvoidmain(String args[]) { intn1=20,n2=10; //Defining Static Integer values n1*=n2; // or n1=n1*n2; System.out.println("Multiplicatation : "+n1); } } Java Program to find Given Number is Prime or Not /* Write a Java program to Find whether number is Prime or Not. */ classPrimeNumber { publicstaticvoidmain(String args[]) { intnumber = Integer.parseInt(args[0]); intflag=0; for(inti=2; i<number; i++) { if(number%i==0) { System.out.println(number+" is not a Prime Number"); flag = 1; break; } } if(flag==0) System.out.println(number+" is a Prime Number"); } } Java Program to Find Whether Given number is Armstrong or not /*Write a program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ classArmstrong { publicstaticvoidmain(String args[]) {<br> //Read Command Line Argument intnum = Integer.parseInt(args[0]); intn = num; //use to compare at If stmt intcheck=0,remainder;
  • 12. while(num> 0) { remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } } Java Program to Find Factorial of a Given Number using While Loop importjava.io.*; importjava.lang.*; classFactorial { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter Number: "); intnum=Integer.parseInt(br.readLine()); intresult = 1; while(num>0) { result = result * num; num--; } System.out.println("Factorial of Given Number is : "+result); } } Java Program to Find Maximum of Two Numbers classMaxoftwo { publicstaticvoidmain(String args[]) { //taking value as command line argument. //Converting String format to Integer value
  • 13. inti = Integer.parseInt(args[0]); intj = Integer.parseInt(args[1]); if(i> j) System.out.println(i+" is greater than "+j); else System.out.println(j+" is greater than "+i); } } Java Program to Print Prime Numbers up to Given Number importjava.io.*; importjava.lang.*; classPrime { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in)); System.out.println("Enter the value: "); intn=Integer.parseInt(br.readLine()); System.out.println("Prime numbers are: "); for(inti=1;i<=n;i++) { intp=0; for(intj=1;j<=i;j++) { if(i%j==0) p++; } if(p==2) System.out.print(" "+i); } } } Java Program for Fibonacci Series importjava.io.*; importjava.lang.*; classFibonacci { publicstaticvoidmain(String args[]) throwsIOException { BufferedReaderbr=newBufferedReader(newInputStreamReader(System.in));
  • 14. System.out.println("Enter the value:"); intn=Integer.parseInt(br.readLine()); intt1=0,t2=1; System.out.print("Fibonacci Series is "+t1+" "+t2); for(inti=0; i<n; i++) { intt3=t1+t2; t1=t2; t2=t3; System.out.print(" "+t3); } } }