You are on page 1of 32

JAVA PROJECT FILE (X)

Write a program find the charge of Phone bill according to given tariff Unit <100 100 to 200 >200 STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 Cost/unit 0.80 1.00 1.50 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES THE VALUE FROM THE USER CALCULATE THE CHARGES PRINT THE CHARGES

import java.io.*; class charge { public static void main(String[] args) { int d; BufferedReader ob= new BufferedReader (new InputStreamRaeder(System.in)); string x=ob.readLine(); u= Integer.parseInt(x); if (u<100) float charge=0.80*d; if (u>100&&u<=200) float charge = (100*0.80+(u-100)*1); if (u>200) float charge = (100*0.80+10*1+(u-200)*1.50); System.out.println(+charge); } } Input :- 50 Output :- 40 Variable Description : u int take the input from user charge float store the total charge

JAVA PROJECT FILE (X)

Write a Program to print 1 12 123 1234 STEP -1 STEP -2 STEP -3 STEP -4 STEP 5 class Peramid { public static void main(String[] args) { for(int i=1;i<=4;i++) { for(int j=1;j<=i;j++) { System.out.print(+j); } System.out.println(); } } Output : 1 12 123 1234 Variable Description : i int use in outer for loop j int use in inner for loop WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM FOR LOOP I1 TO 4 FOR LOOP J1 TO I PRINT THE J

JAVA PROJECT FILE (X)

Write a Program to print 55555 4444 333 22 1 STEP -1 STEP -2 STEP -3 STEP -4 STEP 5 class Peramid { public static void main(String[] args) { for(int i=5;i>=1;i--) { for(int j=5;j<=i;j--) { System.out.print(+i); } System.out.println(); } } } WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM FOR LOOP I5 TO 1 FOR LOOP J1 TO I PRINT THE I

JAVA PROJECT FILE (X)

j int use in inner for loop

Write a program to print all prime number between 1 to 20 STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP 7 import java.io.*; class Prime { public static void main(String args[]) { int n ; for (n=1;n<20;n++) { int c=0; for (int i=1;i<=n;i++) { if(n%i == 0) c=c+1; } if (c= =2) System.out.println(+n); } } } Output : 1 2 3 5 7 11 13 17 19 4 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM FOR LOOP N1 TO 20 C 0 FOR LOOP I1 TO N IF C=2 PRINT THE N

JAVA PROJECT FILE (X)

Variable Description : n int use in outer for loop i int use in inner for loop c int act as a counter variable.

Write a program to print out how many number of uppercase ,lowercase , and digit present in the given string . STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP -7 STEP -8 STEP -9 STEP -10 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM L = S.LENTH() V,G,D,S1 0 FOR LOOP I1 TO N IF(H65 TO 90) V V+1 IF(H97 TO 122) L L+1 IF(H48 TO 57) D D+1 ELSE S1 S1+1 PRINT THE V,L,D,S1

import java.lang.*; class Address { public static void main(String[] args) { String s="My address is B/139,Aliganj,Lucknow-266006"; int l=s.length(); int u=0,g=0,d=0,s1=0; for(int i=0;i<l;i++) { char ch=s.charAt(i); int h=ch; if(h>=65&&h<=90) u=u+1; if(h>=97&&h<=122) l=l+1; else if(h>=48&&h<=57) d=d+1; else s1=s1+1; } System.out.print( "Upper case="); System.out.println( +u); System.out.print( "Lower case="); System.out.println( +l); System.out.print( "Digit="); System.out.println( +d); System.out.print("Special case="); System.out.println( +s1); 5

JAVA PROJECT FILE (X)

} } Output : Upper case=4 Lower case=22 Digit=9 Special case= 7 Variable Description : s string store the string l int stores the length of the string. i int use for loop u int act as a counter variable l int act as a counter variable. d int act as a counter variable s1 int act as a counter variable ch char store the each character in the string h int stores the ASCII value of each character.

JAVA PROJECT FILE (X)

Write a program replace the a particular word in given string. STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP -7 import java.lang.*; class Replace { public static void main(String args[]) { String s="I am a girl"; int l=s.length(); int P=s.indexOf("girl"); String St=s.substring(0,P); String str =St+"boy"; System.out.println("output is "); System.out.println(str); } } WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM L S.LENTH() PS.INDEXOF("GIRL") STS.SUBSTRING(0,P) STRST+"BOY" PRINT THE STR

Input : I am a girl Output : output is I am a boy

Variable Description : s string store the string l int stores the length of the string. P int stores the position that character St string store the string 7

JAVA PROJECT FILE (X)

s string store the string

Sum = x1/2+ x2/3+x100/101 STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP 7 import java.io.*; import java.lang.*; class series { public static void main(String args[]) throws IOException { int x; BufferedReader ob = new BufferedReader (new InputStreamReader(System.in)); String y=ob. readLine(); x=Integer.parseInt(y); float sum = 0; for(int i= 1;i<=100;i++ ) { sum = sum + Math.pow(x,i)/(i+1); } System.out.print(+sum); } } } WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES THE VALUE FROM THE USER SUM0 FOR LOOP I1 TO 100 SUM SUM + MATH.POW(X,I)/ (I+1) PRINT THE SUM

Variable Description : i int use for loop sum int store the summation of the series

JAVA PROJECT FILE (X)

Write a program to takes 2 integer number from user and print they are twinprime or not STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP 7 STEP -8 STEP 9 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES 2 VALUES FROM THE USER C10, C20 FOR LOOP I1 TO A / FOR LOOP I1 TO B IF C1=2,C2=2,A-B=2,B-A=2 PRINT A,B TWINEPRIME ELSE PRINT A,B NOT TWINEPRIME

import java.io.*; class Twinprime { public static void main(String[] args)throws IOException { int a,b; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the 1st no."); String x=br.readLine(); a=Integer.parseInt(x); System.out.println("Enter the 2nd no."); String y=br.readLine(); b=Integer.parseInt(y); int c1=0; for(int i=1;i<=a;i++) { if(a%i==0) c1=c1+ 1; } int c2=0; for(int i=1;i<=b;i++) { if(b%i==0) c2=c2+1; } if((c1==2&&c2==2)&&(a-b==2||b-a==2)) { System.out.print(+a); System.out.print(","); 9

JAVA PROJECT FILE (X)

System.out.print(+b); System.out.print("are twin prime"); } else System.out.print("are not twin prime"); } } Input : Enter the 1st no : 11 Enter the 2nd no :13 Output : 11,13 are twin prime Variable Description : i int use for loop c1 int act as a counter variable c2 int act as a counter variable.

10

JAVA PROJECT FILE (X)

Write a program to takes a integer number from user and print they are palprime or not STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP 7 STEP -8 STEP 9 STEP 10 STEP -11 STEP -12 STEP 13 STEP -14 STEP 15 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES VALUE FROM THE USER REV0, C20, XA WHILE (A>0) INT R A % 10 REV REV*10 +R INT Q A/10 A Q IF REV= X FOR LOOP I1 TO X IF C1=2,C2=2,A-B=2,B-A=2 PRINT A,B TWINEPRIME ELSE PRINT A,B NOT TWINEPRIME

import java.io.*; class palprime { public static void main(String[] args) throws IOException { int x; BufferedReader ob = new BufferedReader(new InputStreamReader(System.in)); String y=ob.readLine(); x=Integer.parseInt(y); int a = x; int rev = 0, c =0; while (a>0) { int r = a % 10; rev = rev*10 +r; int q = a/10; a = q; } if (x == rev) { for( int j =1;j<=x;j=j+1) { if(x%j == 0) 11

JAVA PROJECT FILE (X)

c = c+1; } if(c = =2) { System.out.print(+x ); System.out.print("is palprime"); } else { System.out.print("notpalprimr"); } } Variable Description : j int use for loop c int act as a counter variable rev int store the reverse value q int store the quosent value r int store the remainder value

12

JAVA PROJECT FILE (X)

Write a program to takes any number from user and print each digit in alphabetically STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP 7 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES THE VALUE FROM THE USER R=W%10 SWITCH(R) PRINT THE OUTPUT

import java.io.*; class Word { public static void main(String[] args) throws IOException { int w; BufferReader bf=new BufferdReader(new InputStreamReader (System .in)); System.out.println("Enter the no."); String x =bf.readLine(); w= Integer.parseInt(x); int r=w%10; string z; switch(r); { case 0:z="zero"; break; case 1:z="one"; break; case 2:z="two" break; case 3:z="three"; break; case 4:z="four"; break; case 5:z="five" break; case 6:z="six"; break; case 7:z="seven"; break; case 8:z="eight" break; 13

JAVA PROJECT FILE (X)

case 9:z="nine"; break; default: System.out.println("the value is not matching" ); } System.out.println(z); } } Input : Enter the no : 17 Output : seven one Variable Description : z string store the string r int store the remainder value

14

JAVA PROJECT FILE (X)

Write a program to find the sum of the series 13+23+33++a3 STEP -1 STEP -2 STEP -3 STEP -4 STEP -5 STEP -6 STEP 7 WRITE THE CLASS NAME WRITE THE MAIN IN THE PROGRAM TAKES THE VALUE FROM THE USER SUM0 FOR LOOP I1 TO a SUM SUM + MATH.POW(a,3) PRINT THE SUM

import java.io.*; import java.lang.*; class Series { public static void main(String args[]) throws IOException { int a; BufferedReader Br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the value of a."); String x=Br.readLine(); a=Integer.parseInt(x); double Sum=0; for(int i=1;i<=a;i++) { Sum=Sum+ Math.pow(i,3); } System.out.print(+Sum); } } Input : Enter the value of a 5 Output : 225 Variable Description : i int use for loop Sum int store the summation of the series 15

JAVA PROJECT FILE (X)

WAP to enter any block and print how many sentence, vowel, word present in each string STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP 10 STEP 11 STEP 12 STEP 13 STEP 14 STEP 15 START THE CLASS START THE MAIN ENTER THE BLOCK SNS+ LSN.LENGTH() V0,W0,ST0 FOR(INT I=0;I<1;I++) CHAR CHSN.CHAR AT(I); IF(CH!='.'||CH!='!'||CH!='?') IF(CH=='A'|| CH=='E'|| CH=='O'||CH=='I' ||CH=='U') W=W+1 ELSE V=V+1 ELSE IF ST= ST+1 PRINT THE OUTPUT

import java io.*; import java lang.*; class Word { public static void main(String []args)throws IO Exception { String S; BufferedReader br=new BufferedReader(new Input Stream Reader(System.in)); S=br.readline(); String Sn=" "+s; int l=Sn.length(); intV=0,W=0,st=0; System.out.print ln("sentence vowel word"); for(int i=0;i<1;i++) { char ch=Sn.char At(i); if(ch!='.'||ch!='!'||ch!='?') { if(ch=='A'||ch=='a'||ch=='E'||ch=='e'||ch=='O'||ch=='o'||ch=='i'||ch=='I' ||ch=='U'||ch=='u') { V=V+1 16

JAVA PROJECT FILE (X)

} else if (ch==' ') W=W+1 } else { st= st+1; System.out.println(+st" "+V" "+W); V=0; W=0; } } } Input : java is a programming language. BlueJ run java program. Output: sentence 1 2 vowel 11 7 word 5 4

Variable Description : S,Sn string l int V,W,st int ch char

store the string stores the length of the string. act as a counter variable. store the each character in the string

17

JAVA PROJECT FILE (X)

Write a program to find the factorial of a number using recursive function STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 START THE CLASS START THE FUNCTION (INT F) IF F = 0 RETURN 0 ELSE IF F =1 RETURN 1 ELSE RETURN F*FACT(F-1) START THE MAIN ENTER THE VALUES FROM THE USER PASS THE PARAMITER THROUGH FUNCTION PRINT THE OUTPUT

import java.io.*; class recursion { int fact(int f) { if(f==0) return 0; else if(f==1) return 1; else return f*fact(f-1); } public static void main(String args[])throws IOException {BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); recursion r=new recursion(); System.out.println(Enter any number); int n=Integer.parseInt(ob.readLine()); int f=r.fact(n); System.out.println(Factorial of the number is : +f); } } Output Enter any number 5 Factorial of the number is : 120 18

JAVA PROJECT FILE (X)

Write a program to create a single dimensional array of n element and print the array elements in reverse order. STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES FOR I N-1 TO 0 PRINT I

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,i; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); } System.out.println(Array in reverse order \n); for(i=n-1;i>=0;i--) { System.out.print(ar[i]+ ); } } } Output Enter the length of the array: 5 Enter 5 elements 12 23 19

JAVA PROJECT FILE (X)

34 45 56 Array in reverse order 56 45 34 23 12 Variable Description : n int stores the length of the array. i int stores all numbers from n-1 to 0, act as a counter variable. ar[] int Stores n elements.

20

JAVA PROJECT FILE (X)

WAP to create an array of n elements. Enter a number to search in array if found print its position in list else print element not found. (Use linear search technique). STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP 10 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES ENTER THE SEARCH VALUE FOR I 0 TO N IF AR[I] = VALUE POSITION I PRINT POSITION PRINT VALUE

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,I,num,flag=0; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); } System.out.println(Enter a number to be Searched :); num=Integer.parseInt(ob.readLine()); for(i=0;i<n;i++) { if(ar[i]==num) { flag=1; break; } } 21

JAVA PROJECT FILE (X)

if(flag==1) System.out.println(The number is found at position :+(i+1)); else System.out.println(The number is not found); } } Output Enter the length of the array: 5 Enter 5 elements 12 23 34 45 56 Enter a number to be Searched : 34 The number is found at position : 3

22

JAVA PROJECT FILE (X)

WAP to create an array of n elements. Enter a number to search in array if found print its position in list else print element not found. (Use Binary search technique). STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP 10 STEP 11 STEP 12 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES ENTER THE SEARCH VALUE FOR I 0 TO N IF AR[I] = VALUE POSITION I PRINT POSITION PRINT VALUE ELSE NOT FOUND THE ENTERED NUMBER

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,I,U,mid,num,flag=0; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); } System.out.println(Enter a number to be Searched :); num=Integer.parseInt(ob.readLine()); L=0;U=n-1; while(L<=U) { mid=(U+L)/2; if(ar[mid]==num) 23

JAVA PROJECT FILE (X)

{ flag=1; break; } else if(ar[mid]>num) { U=mid-1; } else { L=mid+1; } } if(flag==1) System.out.println(The number is found at position :+(mid+1)); else System.out.println(The number is not found); } } Output Enter the length of the array: 5 Enter 5 elements 12 23 34 45 56 Enter a number to be Searched : 34 The number is found at position : 3 Variable Description : n int stores the length of the array. ar[] int Stores n elements. num int Store the number inputted by the user to search. flag int Status variable becomes 1 when the number if found else 0. L int Store the value of upper bound. U int Store the value of Lower bound. Mid int Stores the middleposition of the array.

24

JAVA PROJECT FILE (X)

WAP to create an array of n elements and print the array in ascending order using using bubble sort technique. STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP 10 STEP 11 STEP 12 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES TEMP 0 FOR I 0 TO N FOR J 0 TO N-I IF(AR[J]>AR[J+1]) TEMPAR[J] AR[J]AR[J+1] AR[J+1]TEMP PRINT THE ARRAY IN SORTED ORDER

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,i,j,temp; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); } for(i=0;i<n;i++) { for(j=0;j<n-i-1;j++) { if(ar[j]>ar[j+1]) { 25

JAVA PROJECT FILE (X)

temp=ar[j]; ar[j]=ar[j+1]; ar[j+1]=temp; }}} System.out.println(Sorted array is :); for(i=0;i<n;i++) { System.out.print(ar[i]+ ); } } } Output : Enter the length of the array: 5 Enter 5 elements 12 45 89 3 66 Sorted array is : 3 12 45 66 89

Variable Description : n int stores the length of the array. ar[] int Stores n elements. i int stores all numbers from 0 to n-1, act as a counter variable. j int stores all numbers from 0 to n-i-1, act as a counter variable. temp int Store the value of the left side element temporarily.

26

JAVA PROJECT FILE (X)

WAP create an array of n elements and print the array in ascending order using selection sort technique. STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 STEP 9 STEP 10 STEP 11 STEP 12 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES TEMP 0 FOR I 0 TO N FOR J I+1 TO N IF(AR[J]>AR[J+1]) TEMPAR[J] AR[J]AR[J+1] AR[J+1]TEMP PRINT THE ARRAY IN SORTED ORDER

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,i,j,temp; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); } int temp; for(int i=0;i<n;i++) { for(j=i+1;j<n;j++) {if(ar[j]>ar[j]) 27

JAVA PROJECT FILE (X)

{ temp=ar[i]; ar[i]=ar[j]; ar[j]=temp; } } } } System.out.println(Sorted array is :); for(i=0;i<n;i++) { System.out.print(ar[i]+ );} } } Output : Enter the length of the array: 5 Enter 5 elements 12 45 89 3 66 Sorted array is : 3 12 45 66 89 Variable Description : n int stores the length of the array. ar[] int Stores n elements. i int stores all numbers from 0 to n-2, act as a counter variable. j int stores all numbers from i+1 to n-1, act as a counter variable. temp int Store the value of the small element temporarily.

28

JAVA PROJECT FILE (X)

Program to create an array of n elements and print the sum of all elements. STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 START THE CLASS START THE MAIN ENTER THE LENTH OF SINGAL DIAMENTION ARRAY ENTER THE VALUES SUM 0 FOR I 0 TO N SUMSUM+ AR[I] PRINT THE SUM

import java.io.*; class array { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); int n,i,sum=0; int ar[]=new int[100]; System.out.println(Enter the length of the array :); n=Integer.parseInt(ob.readLine()); System.out.println(Enter +n+ Elements :); for(i=0;i<n;i++) { ar[i]=Integer.parseInt(ob.readLine()); sum=sum+ar[i]; } System.out.println(Sum is :+sum); } } Output : Enter the length of the array: 5 Enter 5 elements 10 20 29

JAVA PROJECT FILE (X)

30 40 50 Sum is : 150 Variable Description : n int stores the length of the array. ar[] int Stores n elements. i int stores all numbers from 1 to n, act as a counter variable. sum int Store the sum of n elements.

WAP implement function Overloading. STEP 1 STEP 2 STEP 3 STEP 4 STEP 5 STEP 6 STEP 7 STEP 8 START THE CLASS START THE FUNCTION (DOUBLE R) START THE FUNCTION (FLOAT L, FLOAT B) START THE FUNCTION (FLOAT S) START THE MAIN ENTER THE VALUES FROM THE USER PASS THE PARAMITER THROUGH FUNCTION PRINT THE OUTPUT