Professional Documents
Culture Documents
JAVA Comp Project
JAVA Comp Project
ALGORITHM:
STEP 1 - START
STEP 2 - INPUT sales
STEP 3 - IF (sales>=100000) THEN comm=0.25 *sales
OTHERWISE GOTO STEP 4
STEP 4 - IF (sales>=80000) THEN comm=0.225*sales OTHERWISE
GOTO STEP 5
STEP 5 - IF (sales>=60000) THEN comm=0.2 *sales OTHERWISE
GOTO STEP 6
STEP 6 - IF (sales>=40000) THEN comm=0.15 *sales OTHERWISE
GOTO STEP 7
STEP 7 - comm=0.125*sales
STEP 8 - PRINT "Commission of the employee="+comm
STEP 9 - END
m
PROGRAM:
import java.io.*;
class SalesComission
double sales,comm;
System.out.println(“Enter sales”);
if(sales>=100000)
comm=0.25*sales;
else if(sales>=80000)
comm=0.225*sales;
else if(sales>=60000)
comm=0.2*sales;
else if(sales>=40000)
comm=0.15*sales;
else comm=0.125*sales;
Output
enter sales
—————————————————————————————
2130000
—————————————————————————————
employee=532500.0
Progra -2
PROGRAM:
{
String num;
int base;
num=””;
while (dec!=0)
division dec=dec/base;
System.out.println("Binary Number="+num);
}}//class close
m
Output
Input - “435”
—————————————————————————————
Progra - 3
1 to 100.
Two prime numbers are called twin primes if there is present only
prime numbers whose difference is two are called twin primes. For
example, (3,5) are twin primes, since the difference between the
two numbers 5 – 3 = 2.
m
PROGRAM:
class TwinPrimeNumbers
Boolean checkPrime(int N)
int c=0;
if (N%i==0)
c++;
return c=2;
boolean r1=obj.checkPrime(num);
boolean r2=obj.checkPrime(num+2);
Output
3, 5
5, 7
11, 13
17, 19
29, 31
41, 43
59, 61
71, 73
Progra - 4
ALGORITHM:
STEP 1: START
STEP 6: END
m
fi
PROGRAM:
int sumOfDigits = 0;
sumOfDigits = 0; }
}}
Output
Progra - 5
ALGORITHM:
STEP 1: START
STEP 4: INPUT THE ELEMENTS IN THE ARRAY IN ARRAY FROM THE USER
STEP 8: IF MID VALUE MATCHES WITH THE VALUE TO BE SEARCHED THEN GOTO
STEP 11
PROGRAM:
int i, num, item, array[], rst, last, middle; Scanner sc= new
Scanner(System.in); System.out.println("Enter number of
elements:"); num = sc.nextInt();
rst = 0;
last = num - 1;
rst = middle + 1;
} else
last = middle - 1; }
} }
fi
fi
fi
fi
fi
fi
fi
Output
Enter 7 integers
66
77
99
77 found at location 4
Progra - 6
ALGORITHM:
STEP 1: START
STEP 2: INPUT a[ ]
STEP 4: ag = -1
fl
m
PROGRAM:
import java.io.*;
class SelectionSort
{int n,i;
for(i=0;i<n;i++)
{a[i] = Integer.parseInt(br.readLine());
}}
{System.out.println();
for(i=0;i<n;i++)
{System.out.print(a[i]+" ");
}}
for(i=0;i<n-1;i++)
{min =i;
for(j=i+1;j<n;j++)
{if(a[j]<a[min])
min =j;
if(min!=i)
{temp = a[i];
a[i] =a[min];
a[min] = temp;
}}}
ff
ff
public static void main(String args[]) throws IOException //main
function {SelectionSort x = new SelectionSort(5);
x.input();
x.display();
x.sort();
x.display();
}}
Output
enter elements 45
7878
878
98
Before sorting -
Progra - 7
ALGORITHM:
STEP 1: START
STEP 2: INPUT a[ ]
PROGRAM:
import java.io.*;
class MatrixSum
{for(y=0;y<5;y++)
}}
System.out.println("Array -");
for(x=0;x<5;x++)
{for(y=0;y<5;y++)
{System.out.print(a[x][y]+" ");
System.out.print("\n");
for(x=0;x<5;x++)
{for(y=0;y<5;y++)
{Sum=Sum+a[x][y];
}}
}}
ff
ff
Output
25
Array –
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
Progra - 8
ALGORITHM:
STEP 1: START
STEP 2: INPUT a[ ]
fi
PROGRAM:
import java.io.*;
class ColoumnSum
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}
System.out.println("Array -");
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{System.out.print(a[x][y]+" ");
}System.out.print("\n");
for(y=0;y<4;y++)
{for(x=0;x<4;x++)
{Sum=Sum+a[x][y];
Sum=0;
}}}
ff
ff
Output
16
Array-
1234
5678
9 10 11 12
13 14 15 16
Sum of column 1 is 28
Sum of column 2 is 32
Sum of column 3 is 36
Sum of column 4 is 40
Progra - 9
ALGORITHM:
STEP 1: START
STEP 2: INPUT a[ ]
STEP 9: Sum = 0
fi
PROGRAM:
import java.io.*;
class DiagonalSum
int x,y,z,Sum=0;
a[x][y]=z;
}}
System.out.println("Array -");
for(x=0;x<4;x++)
{for(y=0;y<4;y++)
{System.out.print(a[x][y]+" ");
System.out.print("\n");
y=0;
for(x=0;x<4;x++)
{Sum=Sum+a[x][y];
y=y+1;
}}
ff
ff
Output
16
Array-
1234
5678
9 10 11 12
13 14 15 16
Sum of Diagonal is 34
Progra - 10
ALGORITHM:
STEP 1: START
STEP 3: z = a.length()
STEP 6: IF (a.charAt(y)==‘a’||a.charAt(y)==‘e’||a.charAt(y)==‘i’||a.charAt(y)==‘o’||
a.charAt(y)==‘u’) THEN x=x+1 OTHERWISE b = b+1
STEP 7: PRINT x
STEP 8: PRINT b
STEP 9: END
PROGRAM:
import java.io.*;
class Vowels
int z=a.length(),y,x=0,b=0;
else b++;
}}
ff
ff
Output
Progra - 11
Pascal’s Triangle
ALGORITHM:
STEP 1: START
STEP 2: pas[0]=1
STEP 3: IF i=0 THEN GOTO STEP 4
STEP 4: IF j=0 THEN GOTO STEP 5
STEP 5: PRINT pas[j]+””
STEP 6: i++ & IF i<n GOTO STEP 4
STEP 7: j=0 & IF j<=i GOTO STEP 5
STEP 8: IF j=i+1 THEN GOTO STEP 7
STEP 9: pas[j]=pas[j]+pas[j-1]
STEP 10: j - - & IF j>0 GOTO STEP 9
STEP 11: END
PROGRAM:
import java.io.*;
class Pascal
pas[0] = 1;
System.out.print(pas[j]+" ");
System.out.println( );
pas[j]=pas[j]+pas[j-1];
}}}
ff
m
ff
Output
Progra - 12
ALGORITHM:
STEP 1: START
STEP 2: a=“Computer Applications”
STEP 3: x=0
STEP 4: FROM z=0 to z<a.length() REPEAT STEP 5
STEP 5: if(a.charAt(z)==‘a’||a.charAt(z)==‘i’||a.charAt(z)==’e’||a.charAt(z)==’o’||a.charAt(z)==’u’) tHEN
a.setCharAt(z.””)
STEP 6: PRINT “New String-“+a
STEP 7: END
PROGRAM:
import java.io.*;
class VowelReplace
int z=0;
}}
ff
ff
m
ff
ff
Output
Progra - 13
PROGRAM:
import java.io.*;
class Pattern
{int i,sp,j,k,l;
l=s.length();
for(i=0;i<l;i++)
k++;
System.out.println(" ");
}}}
ff
m
ff
Output
Progra - 14
Decoding of string
PROGRAM:
import java.io.*;
class Decode
String name=br.readLine();
System.out.println(“Enter number:”);
int n=Integer.parseInt(br.readLine());
int j,i,l,c=0,y,n1;
l=name.length();
for(i=0;i<l;i++)
{char c1=name.charAt(i);
{c=(int)c1 ;
catch(NumberFormatException e)
{}
if(n>0)
{if((c+n)<=90)
/*Decoding String*/
System.out.print((char)(c+n));
else {c=c+n;
c=c%10;
c=65+(c-1);
System.out.print((char)(c));
}}
m
ff
ff
Output
Progra - 15
Sales Commission
Sales Commission
>=100000 25% of sales
80000-99999 22.5% of sales
60000-79999 20% of sales
40000-59999 15% of sales
<40000 12.5% of sales
PROGRAM:
import java.io.*;
class SalesComission
{double sales,comm;
sales=Double.parseDouble(aa.readLine());
if(sales>=100000) comm=0.25*sales;
else if(sales>=60000)
comm=0.2*sales;
else if(sales>=40000)
comm=0.15*sales;
else comm=0.125*sales;
ff
Output
Progra - 16
PROGRAM:
import java.io.*;
String hund[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
String ten[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
String unit[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
Output
Progra - 17
Date Program
PROGRAM:
import java.io.*;
class Day2Date
{int a[ ] = { 31,28,31,30,31,30,31,31,30,31,30,31 } ;
a[1] =29;
int t=0,s=0;
while( t < n)
{t =t + a[s++];
int d = n + a[--s] - t;
if( d == 1|| d == 21 || d == 31 )
if( d == 2 || d == 22 )
if( d == 3|| d == 23 )
}}
int n = Integer.parseInt(br.readLine());
int yr = Integer.parseInt(br.readLine());
obj.calc(n,yr);
}}
ff
m
ff
Output
Progra - 18
PROGRAM:
import java.io.*;
class C2F
double temp=ob.convert(Double.parseDouble(br.readLine()));
{double far=1.8*celcius+32.0;
return far;
}}
ff
m
ff
Output
Progra - 19
GCD Series
PROGRAM:
import java.io.*;
class GCD
//accepting nos.
return p;
ff
Output
Progra - 20
PROGRAM:
import java.io.*;
class Frequency
{p=0;
{int ii;
l=str.length();
System.out.print(str);
for(i=0;i<l;i++)
{char a=str.charAt(i);
for(ii=0;ii<l;ii++)
{char b = str.charAt(ii);
if (a==b)
freq=freq+1;
freq=0;
}}
x.count(str);
}}
ff
m
ff
Output
Progra - 21
Number in Words
PROGRAM:
import java.io.*;
class Num2Words
//main function
int z,g;
String
x[]={“”,"Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","
Eighteen","Nineteen"};
g=amt/10;
if(g!=1)
System.out.println(x2[g-1]+" "+x1[z]);
else System.out.println(x[amt-9]);
}}
ff
m
fi
ff
Output
Progra - 22
PROGRAM:
class APSeries
{a = d = 0;
APSeries(double a,double d)
{this.a = a;
this.d = d;
double nTHTerm(int n)
{return (a+(n-1)*d);
double Sum(int n)
{return (n*(a+nTHTerm(n))/2);
for(int i=1;i<=n;i++)
{System.out.print(nTHTerm(i)+" ");
System.out.print("\n\tSum :"+Sum(n));
Sum(n);
showSeries(n);
}
ff
m
ff
ff
Output
Progra - 23
PROGRAM:
class APSeries
{a = d = 0;
APSeries(double a,double d)
{this.a = a;
this.d = d;
double nTHTerm(int n)
{return (a+(n-1)*d);
double Sum(int n)
{return (n*(a+nTHTerm(n))/2);
for(int i=1;i<=n;i++)
{System.out.print(nTHTerm(i)+" ");
System.out.print("\n\tSum :"+Sum(n));
Sum(n);
showSeries(n);
}
ff
m
ff
ff
Output
Progra - 24
PROGRAM:
import java.io.*;
class Factorial
int n = Integer.parseInt(br.readLine());
long f = obj.fact(n);
System.out.println("Factorial ="+f);
{if(n<2)
return 1;
}}
ff
m
ff
Output
Progra - 25
PROGRAM:
import java.io.*;
class Fibonacci
int n = Integer.parseInt(br.readLine());
System.out.println();
for(int i=1;i<=n;i++)
System.out.print(f+" ");
}}
{if(n<=1)
return n;
else
}}
ff
fi
m
fi
fi
fi
ff
Output
Progra - 26
Spiram Matrix
PROGRAM:
import java.io.*;
class SpiralMatrix
{int a[][],r,c,k1=2,k2=3,p=0,co=0,re=0;
r=l/2;c=r-1;
if(l%2==0)
System.exit(0);
while(p!=(int)Math.pow(l,2))
{if(co!=0)
re=1;
for(int ri=1;ri<=k1-re;ri++)
{p++;c++;if(c==l)break;a[r][c]=p;}
if(c==l)break;
for(int dw=1;dw<=k1-1;dw++)
{p++;r++;a[r][c]=p;}
for(int le=1;le<=k2-1;le++)
{p++;c--;a[r][c]=p;}
for(int up=1;up<=k2-1;up++)
{p++;r--;a[r][c]=p;}
k1=k1+2;
k2=k2+2;
co++;
for(int y=0;y<l;y++)
{for(int yy=0;yy<l;yy++)
System.out.print("\t"+a[y][yy]);
System.out.println();
System.out.println();
}}}
ff
m
ff
Output
Progra - 27
Magic Number
PROGRAM:
import java.io.*;
class MagicSquare
for(num=1;num<=n*n;num++) {r--;
c++;
if(r==-1)
r=n-1; if(c>n-1)
c--;
arr[r][c]=num;
if(r==0&&c==0)
{r=n-1;
c=1;
arr[r][c]=++num;
if(c==n-1&&r==0) arr[++r][c]=++num;
}}}
ff
m
ff
Output
Progra - 28
Palindrome Check
PROGRAM:
import java.io.*;
class Palindrome
sb.reverse();
ff
ff
Output
Progra - 29
PROGRAM:
import java.io.*; class Alpha {String str;
int l;
{str = "";
l =0;
//Alpha() constructor
str = br.readLine();
l = str.length();
{int i,j;
char temp;
for(i=0;i<l;i++)
{c[i]= str.charAt(i);
for(i=0;i<l-1;i++)
{for(j=0;j<l-1-i;j++)
{temp = c[j];
c[j] = c[j+1];
c[j+1] = temp;
}}}}
{System.out.println();
for(int i=0;i<l;i++)
{System.out.print(c[i]);
}}
obj.readword();
obj.arrange();
obj.display();
}}
ff
m
ff
Output
Progra - 30
PROGRAM:
import java.io.*;
class DiagonalSum
{for(y=0;y<4;y++)
{z=Integer.parseInt(aa.readLine());
a[x][y]=z;
}}
System.out.println("Array -");
System.out.print("\n"); }
y=0;
//displaying array
}}
ff
m
fi
ff
Output
Bibliography
Site Used Link
Stack Over ow www.stackover ow.com
HackerRank www.hackerrank.com
fl
fl