Trending ▼   ResFinder  

ICSE Class X Notes 2019 : Computer Applications

41 pages, 77 questions, 1 questions with responses, 3 total responses,    3    0
General Numan
Sri R. V. School, Kolar
+Fave Message
 Home > numan90368 >   F Also featured on: dishitaswaika icse

Formatting page ...

Looping Q.No : 1. // Program find sum of digits import java.io.*; class sumdigit { public static void main(String arg[]) throws IOException { int n,r,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); while (n!=0) { r=n%10; s=s+r; n=n/10; } System.out.println("The sum of the digit ="+s); } } Enter Number 2356 The sum of the digit =16 Q.No : 2. // Program to find reverse of the number import java.io.*; class reverse { public static void main(String arg[]) throws IOException { int n,r,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); 1 while (n!=0) { r=n%10; s=s*10+r; n=n/10; } System.out.println("The Reverse of the number ="+s); } } Enter Number 5678 The Reverse of the number =8765 Q.No : 3. // Program to find given number is palindrome or not import java.io.*; class poly { public static void main(String arg[]) throws IOException { int n,m,r,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; while (n!=0) { r=n%10; s=s*10+r; n=n/10; } if(s==m) System.out.println("The Given No is palindrome "+s); else System.out.println("The Given No is Not palindrome "+s); } } Enter Number 232 The Given No is palindrome 232 2 Q.No : 4. // Program to find given number is Armstrong no or not import java.io.*; class Armstrong { public static void main(String arg[]) throws IOException { int n,m,r; double s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; while (n!=0) { r=n%10; s=s+Math.pow(r,3); n=n/10; } if(s==m) System.out.println("The Given No is Armstrong number= "+s); else System.out.println("The Given No is Not Armstrong number "+s); } } Enter Number 153 The Given No is Armstrong number= 153.0 Q.No : 5. // Program Check Neon Number or not import java.io.*; class Neon { public static void main(String arg[]) throws IOException { int n,m,r,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n*n; 3 while (m!=0) { r=m%10; s=s+r; m=m/10; } if(s==n) System.out.println("The Given No Neon Number= "+s); else System.out.println("The Given No is Not Neon Number "+s); } } Q.No : 6. // Program Check Duck Number or not import java.io.*; class Duck { public static void main(String arg[]) throws IOException { int n,m,r,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; while (n!=0) { r=n%10; if(r==0) { s=1; break; } n=n/10; } if(s==1) System.out.println("The Given No Duck Number= "+m); else System.out.println("The Given No is Not Duck Number "+m); } } 4 Enter Number 5063 The Given No Duck Number= 5063 Q.No : 7. // Program to check special number or not import java.io.*; class special { public static void main(String arg[]) throws IOException { int n,m,r,i,s=0,f=1; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; while (n!=0) { r=n%10; f=1; for(i=1;i<=r;i++) f=f*i; s=s+f; n=n/10; } if(s==m) System.out.println("The Given No is Special Number "+m); else System.out.println("The Given No is Not Special Number "+m); } } Enter Number 145 The Given No is Special Number 145 5 Q.No : 8. // Program finding factorial of N import java.io.*; class factorial { public static void main(String arg[]) throws IOException { int n,i,f=1; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); for(i=1;i<=n;i++) f=f*i; System.out.println("The factorial value="+f); } } Enter Number 5 The factorial value=120 Q.No : 9 // Program check perfect number or not import java.io.*; class perfect { public static void main(String arg[]) throws IOException { int n,i,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); for(i=1;i<n;i++) { if(n%i==0) s=s+i; } if(s==n) System.out.println("Given no is perfect Number="+n); else System.out.println("Given no is Not perfect Number="+n); } } 6 Enter Number 6 Given no is perfect Number=6 Q.No : 10 // Program check composite number or not import java.io.*; class composite { public static void main(String arg[]) throws IOException { int n,i,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); for(i=2;i<n;i++) { if(n%i==0) s=s+1; } if(s>1) System.out.println("Given no is composite Number="+n); else System.out.println("Given no is Not composite Number="+n); } } Enter Number 8 Given no is composite Number=8 Q.No : 11 // Program to check Twin Prime or not import java.io.*; class twinprime { public static void main(String arg[]) throws IOException { int n,m,i,c=0,d=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); 7 System.out.println("Enter First Number"); n=Integer.parseInt(in.readLine()); System.out.println("Enter Second Number"); m=Integer.parseInt(in.readLine()); for(i=1;i<=n;i++) { if (n%i==0) c=c+1; } for(i=1;i<=m;i++) { if (m%i==0) d=d+1; } System.out.println(n+ " " +m); if ((c==d) &&(n-m==2)) System.out.println("Given Nos are Twin Prime Numbers " + "("+m+","+n+")"); else System.out.println("Given Nos are Not Twin Prime Numbers " + "("+m+","+n+")"); } } Q.No : 12 // Program to check Twested Prime or not import java.io.*; class Twested { public static void main(String arg[]) throws IOException { int n,m,i,r,c=0,d=0,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; for(i=1;i<=n;i++) { if (n%i==0) c=c+1; } 8 while (n!=0) { r=n%10; s=s*10+r; n=n/10; } for(i=1;i<=s;i++) { if (s%i==0) d=d+1; } if (c==d) System.out.println("Given No are Twested Prime Number" +m); else System.out.println("Given No are Not a Twested Prime Number" +m); } } Q.No : 13 // Program to check automorphic number import java.io.*; class automorphic { public static void main(String arg[]) throws IOException { int n,m,i,r,c=0,x,y=0,s=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n*n; System.out.println("Given no is " + n); System.out.println("Its square is " + m); x=n; while (n!=0) { n=n/10; c++; } 9 while (m != 0) { r=m%10; s=s*10+r; m=m/10; c--; if(c==0) break; } while (s != 0) { r=s%10; y=y*10+r; s=s/10; } if (x==y) System.out.println("Given No is Automorphic Number" +x); else System.out.println("Given No is not Automorphic Number" +x); } } Q.No : 14 // Program for to display pattern class pattern { public static void main (String arg[]) { int i,j,r,a=1; for(i=1;i<=5;i++) { for(j=1;j<=5;j++) { r=a%10; System.out.print( r+" "); a=a+2; } System.out.println(); a=a+2; } } } 10 13579 35791 57913 79135 91357 Q.No : 15 // Program to display the frequency of each digit import java.io.*; class frequency { public static void main(String arg[]) throws IOException { int n,r,c0=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); while (n != 0) { r=n%10; switch(r) { case 0: c0++; break; case 1: c1++; break; case 2: c2++; break; case 3: c3++; break; case 4: c4++; break; case 5: c5++; break; case 6: c6++; 11 break; case 7: c7++; break; case 8: c8++; break; case 9: c9++; break; } n=n/10; } if (c0!=0) System.out.println("The frequency of 0 = " +c0); if (c1!=0) System.out.println("The frequency of 1 = " +c1); if (c2!=0) System.out.println("The frequency of 2 = " +c2); if (c3!=0) System.out.println("The frequency of 3 = " +c3); if (c4!=0) System.out.println("The frequency of 4 = " +c4); if (c5!=0) System.out.println("The frequency of 5 = " +c5); if (c6!=0) System.out.println("The frequency of 6 = " +c6); if (c7!=0) System.out.println("The frequency of 7 = " +c7); if (c8!=0) System.out.println("The frequency of 8 = " +c8); if (c9!=0) System.out.println("The frequency of 9 = " +c9); } } 12 Q.No : 16 // Program to check unique no or not import java.io.*; class unique { public static void main(String arg[]) throws IOException { int n,m,r,c0=0,c1=0,c2=0,c3=0,c4=0,c5=0,c6=0,c7=0,c8=0,c9=0; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter Number"); n=Integer.parseInt(in.readLine()); m=n; while (n != 0) { r=n%10; switch(r) { case 0: c0++; break; case 1: c1++; break; case 2: c2++; break; case 3: c3++; break; case 4: c4++; break; case 5: c5++; break; case 6: c6++; break; case 7: c7++; break; case 8: c8++; break; case 9: 13 c9++; break; } n=n/10; } if ((c0<2)&&(c1<2) && (c2<2) && (c3<2)&&(c4<2)&&(c5<2)&&(c6<2)&&(c7<2) &&(c8<2)&&(c9<2)) System.out.println("Given No is unique no="+m); else System.out.println("Given No is Not unique no="+m); } } Enter Number 5463 Given No is unique no=5463 14 Arrays Q.No:1 Write a program to enter a set of 10 integers. Sort the numbers in ascending order by using Selection sort technique. Display the sorted array. // Sort the Numbers in Ascending order by using Selection sort import java.io.*; public class sort { public static void main (String args[]) throws IOException { int i,j,t,min; int m[]=new int[10]; InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); System.out.println("Enter 10 Numbers"); for(i=0;i<10;i++) { m[i]=Integer.parseInt(in.readLine()); } for(i=0;i<9;i++) { min=i; for(j=i+1;j<10;j++) { if (m[j]<m[min]) min=j; } t=m[i]; m[i]=m[min]; m[min]=t; } System.out.println("The Numbers arranged in ascending order are.."); for(i=0;i<10;i++) System.out.println(m[i]); } } Q.No:2 Write a program to enter a set of 10 strings. Sort the strings ascending order by using Selection sort technique. Display the sorted array. // Sort the strings in Ascending order by using Selection sort import java.io.*; public class sort { public static void main (String args[]) throws IOException { int i,j,min; String m[]=new String[10]; String t; InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); System.out.println("Enter 10 Names"); for(i=0;i<10;i++) { m[i]=in.readLine(); } for(i=0;i<9;i++) { min=i; for(j=i+1;j<10;j++) { if (m[j].compareTo(m[min])>0) min=j; } t=m[i]; m[i]=m[min]; m[min]=t; } System.out.println("The strings arranged in ascending order are.."); for(i=0;i<10;i++) System.out.println(m[i]); } } Q.No:3 Write a program to enter a set of 10 integers. Sort the numbers in ascending order by using Selection sort technique. Display the sorted array. // Sort the Numbers in Ascending order by using Bubble sort import java.io.*; public class sort { public static void main (String args[]) throws IOException { int i,j,t; int m[]=new int[10]; InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); System.out.println("Enter 10 Numbers"); for(i=0;i<10;i++) { m[i]=Integer.parseInt(in.readLine()); } for(i=0;i<9;i++) { for(j=0;;j<(9-i);j++) { if (m[i]>m[j]) { t=m[i]; m[i]=m[j]; m[j]=t; } } } System.out.println("The Number arranged in ascending order are.."); for(i=0;i<10;i++) System.out.println(m[i]); } } Q.No:4 Write a program to enter a set of 10 strings. Sort the strings ascending order by using Selection sort technique. Display the sorted array. // Sort the Strings in Ascending order by using Bubble sort import java.io.*; public class sort { public static void main (String args[]) throws IOException { int i,j; String m[]=new String[10]; String t; InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); System.out.println("Enter 10 Names"); for(i=0;i<10;i++) { m[i]=in.readLine(); } for(i=0;i<9;i++) { for(j=0;j<(9-i);j++) { if (m[i].compareTo(m[j])>0) { t=m[i]; m[i]=m[j]; m[j]=t; } } } System.out.println("The Names arranged in ascending order are.."); for(i=0;i<10;i++) System.out.println(m[i]); } } Q.No:5 Write a program to accept 10 different numbers in a single dimensional array(SDA). Enter a number and using Binary search technique, check whether a number is present or not in the array. If the number is present then display the message Search Successful otherwise The Search unsuccessful . // To search using Binary Search Technique // To enter the number in either ascending or descending order import java.io.*; public class search { public static void main (String args[]) throws IOException { int i,lb,ub,p,k,ns; lb=0;ub=9;p=0;k=0;ns=0; int m[]=new int[10]; InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); System.out.println("Enter 10 Numbers"); for(i=0;i<10;i++) { System.out.print("Enter Numbers in ascending order in the cell " + (i+1)+":"); m[i]=Integer.parseInt(in.readLine()); } System.out.println("Enter the no. to be searched"); ns=Integer.parseInt(in.readLine()); while(lb<=ub) { p=(lb+ub)/2; if (m[p]<ns) lb=p+1; if(m[p]>ns) ub=p-1; if (m[p]==ns) { k=1; break; } } if(k==1) System.out.println("The search is successful "+ ns+ "Present in the position "+ (p+1)); else System.out.println("The search is unsuccessrul"); } } Q.No:6 Write a program to accept 10 different string in a single dimensional array(SDA). Enter a string and using Binary search technique, check whether a stringis present or not in the array. If the number is present then display the message Search Successful otherwise The Search unsuccessful . // To search using Binary Search Technique // To enter the Names in either ascending or descending order import java.io.*; public class search { public static void main (String args[]) throws IOException { InputStreamReader read = new InputStreamReader (System.in); BufferedReader in= new BufferedReader(read); int i,lb,ub,p,k; lb=0;ub=9;p=0;k=0; String m[]=new String[10]; String ns; System.out.println("Enter 10 Numbers"); for(i=0;i<10;i++) { System.out.print("Enter string in ascending order in the cell " + (i+1)+":"); m[i]=in.readLine(); } System.out.println("Enter the string to be searched"); ns=in.readLine(); while(lb<=ub) { p=(lb+ub)/2; if (m[p].compareTo(ns)<0) lb=p+1; if(m[p].compareTo(ns)>0) ub=p-1; if (m[p].compareTo(ns)==0) { k=1; break; } } if(k==1) System.out.println("The search is successful "+ ns+ "Present in the position "+ (p+1)); else System.out.println("The search is unsuccessrul"); } } Strings Q.No : 1. Write a program to accept a string/ sentence, count and display no of vowels present in the each word. Enter a String MASTERING INFORMATION TECHNOLOGY The vowels present in MASTERING=3 The vowels present in INFORMATION=5 The vowels present in TECHNOLOGY=3 // Count no of vowels import java.io.*; public class vowels { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str,n; int x,y,z,i,count; char b; n=""; count=0; System.out.println("Enter a String"); str=in.readLine(); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b!=' ') { n=n+b; } else { z=n.length(); for(i=0;i<z;i++) { b=(n.charAt(i)); if(b=='a' || b=='e'||b=='i'||b=='o'||b=='u'||b=='A'|| b=='E'||b=='I'||b=='O'||b=='U') count++; } System.out.println("The vowels present in "+n+"="+count); n=""; count=0; } } }} Q.No : 2. Write a program to generate a pattern of a string entered by the user based upon the user s choice. Sample Input : Enter a String : HONESTY IS THE BEST POLICY Enter your choice 1 Sample Output H I T B P Enter your choice 2 Sample Output Y S E T Y // Generate a pattern of a string import java.io.*; public class pattern { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str; int x,y; int ch; char b; System.out.println("Enter a String"); str=in.readLine(); System.out.println("Enter the choice"); System.out.println("1. To display Starting Character"); System.out.println("2. To display Ending Character"); ch=Integer.parseInt(in.readLine()); switch(ch) { case 1: System.out.println("Output Patter is"); str=" "+str; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b==' ') System.out.println(str.charAt(y+1)); } break; case 2: System.out.println("Output Patter is"); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b==' ') System.out.println(str.charAt(y-1)); } break; default: System.out.println("Invalid Choice"); } } } Q.No : 3. Write a program in java to enter a string/sentence and display the longest word and the length of the longest word present in the string. Sample Input : TATA FOOTBALL ACADEMY WILL PLAY AGAINST MOHAN BAGAN Sample output : The longest word : FOOTBALL The length of the word : 8 // Program for Longest Word and Length import java.io.*; public class example { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str,m,n; int x,y; char b; m=""; n=""; System.out.println("Enter a String"); str=in.readLine(); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b==' ') { if (n.length()<m.length()) n=m; m=""; } else { m=m+b; } } System.out.println("The Longest Word is " + n); System.out.println("The Length of word is "+n.length()); } } Q.No : 4. Write a program in java to accept a name (containing three word) and display the surname first followed by the first and middle names. Sample Input: MOHANDAS KARAMCHAND GANDHI Sample Output : GANDHI MOHANDAS KARAMCHAND // Program for display the string import java.io.*; public class example { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str,m,n; int x,y; int count; char b; m=""; n=""; count=0; System.out.println("Enter a String"); str=in.readLine(); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b==' ') { if (count<2) n=n+" " +m; else n=m+" "+n; m=""; count++; } else { m=m+b; } } System.out.println("The Output = " + n); } } Q.No : 5. Write a program in java to accept a sentence and display the longest word of the sentence. The program also display the number of vowels in the longest word. Sample Input: ONE OF THE BEST SCHOOL IS RAJENDRA VIDYALAYA Sample Output : Longest word : VIDYALAYA No of vowels in the longest word : 4 // Program to display longest word and no of vowels import java.io.*; public class example { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str,m,n; int x,y; int count; char b; m=""; n=""; count=0; System.out.println("Enter a String"); str=in.readLine(); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b==' ') { if (n.length()<m.length()) n=m; m=""; } else { m=m+b; } } x=n.length(); for(y=0;y<x;y++) { b=(n.charAt(y)); if(b=='a' || b=='e'||b=='i'||b=='o'||b=='u'||b=='A'|| b=='E'||b=='I'||b=='O'||b=='U') count++; } System.out.println("The Longest Word is " + n); System.out.println("The No of Vowels is " + count); } } Q.No : 6. Write a program to accept a string and check whether the given string is palindrome or not. Sample Input : MADAM Sample Output : Given string is Palindrome : MADAM // To Check given string is palindrome or not import java.io.*; public class palindrome { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str, st1=" "; int x,y; char b; System.out.println("Enter a String"); str=in.readLine(); x=str.length(); for(y=x-1;y>=0;y--) { b=(str.charAt(y)); st1=st1+b; } st1=st1.trim(); if(str.compareTo(st1)==0) System.out.println("Given string is Palindrome " + str); else System.out.println("Given string is Not palindrome " + str); } } Q.No : 7. Write a program to accept a string in upper case and find the frequency of each character present in the string. Enter the String COMPUTER APPLICATIONS Frequency of A is 2 Frequency of C is 2 Frequency of E is 1 Frequency of I is 2 Frequency of L is 1 Frequency of M is 1 Frequency of N is 1 Frequency of O is 2 Frequency of P is 3 Frequency of R is 1 Frequency of S is 1 Frequency of T is 2 Frequency of U is 1 //Frequency of each character import java.io.*; class frequency { public static void main(String arg[])throws IOException { String str,str1,str2; int x,i,j,c=0,s; char b,ch; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); str=str.toUpperCase(); x=str.length(); for(i=65;i<=90;i++) { c=0; for(j=0;j<x;j++) { b=str.charAt(j); s=(int)b; if(s==i) c++; } ch=(char)i; if(c!=0) System.out.println("Frequency of " +ch+" is "+c); } } } Q.No : 8. Write a program to accept a string in upper case and find the frequency of each character present in the string. //Frequency of each character import java.io.*; class frequency { public static void main(String arg[])throws IOException { String str,str1,str2; int x,i,j,c=0,s; char b,ch; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); str=str.toLowerCase(); x=str.length(); for(i=97;i<=122;i++) { c=0; for(j=0;j<x;j++) { b=str.charAt(j); s=(int)b; if(s==i) c++; } ch=(char)i; if(c!=0) System.out.println("Frequency of " +ch+" is "+c); } } } Q.No : 9. Write a program to accept a string and find maximum no of times occurs a character in a given string. Sample Input Enter the String James Gosling Developed Java Sample Output The Character with maximum number of times= e Number of times= 4 // To find maximum no of time occurs a character in a string import java.io.*; class maximum { public static void main(String arg[])throws IOException { String str,str1,str2; int x,i,j,s,c=0,max=0; char b=' ',ch=' '; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); x=str.length(); for(i=65;i<=122;i++) { c=0; if(i>90 && i<=96) continue; for(j=0;j<x;j++) { b=str.charAt(j); s=(int)b; if(s==i) c++; if (max<c) { max=c; ch=(char)i; } } } System.out.println("The Character with maximum number of times= "+ch); System.out.println("Number of times= "+max); } } Q.No : 10. Consider a string as: RED BOTTLE IS IN RED BAG ON RED CARPET Write a program to enter the string through console and replace the token RED with GREEN without using built in function. Output : GREEN BOTTLE IS IN GREEN BAG ON GREEN CARPET import java.io.*; public class Q820 { public static void main(String args[]) throws IOException { InputStreamReader read=new InputStreamReader(System.in); BufferedReader in= new BufferedReader(read); String str,str1="",n=""; int x,y,z,i,count=0; char b; System.out.println("Enter a String"); str=in.readLine(); str=str+" "; x=str.length(); for(y=0;y<x;y++) { b=(str.charAt(y)); if (b!=' ') { n=n+b; } else { if (n.equals("Blue")) str1=str1+" "+"Red"; else str1=str1+" "+n; n=""; } } System.out.println("The New String is="+str1); } } Q.No : 11. A String is said to be Unique , if none of the alphabets present in the string are repeated. Write a program to accept a string and check whether the string is unique or not. The program display a message accordingly. Sample input : COMPUTER Sample output : Unique String import java.io.*; public class unique { public static void main(String arg[])throws IOException { String str,str1,str2; int x,i,j,c=0,s; char b,ch; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); str=str.toUpperCase(); x=str.length(); for(i=0;i<x;i++) { c=0; for(j=0;j<x;j++) { if(str.charAt(i)==str.charAt(j)) c++; } if(c>1) break; } if(c==1) System.out.println("Unique String"); else System.out.println("Not a Unique String"); } } Enter a String Blue bottle is in Blue bag lying on Blue carpet The New String is= Red bottle is in Red bag lying on Red carpet Q.No : 12. Write a Program to display the following pattern Enter the String BLUEJ BLUEJ BLUEB BLUBL BLBLU BBLUE // Ddisplay the pattern import java.io.*; class ser2 { public static void main(String arg[])throws IOException { String str,str1,str2; int x,i,y; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); x=str.length(); y=0; for(i=x;i>=1;i--) { str1=str.substring(0,i); str2=str.substring(0,y); System.out.println(str1+str2); y++; } } } Q.No : 13. Write a Program to display the following pattern Enter the String BLUEJ J EE UUU LLLL BBBBB // Display the pattern import java.io.*; class ser1 { public static void main(String arg[])throws IOException { String str; int x,i,j; char b; InputStreamReader read= new InputStreamReader(System.in); BufferedReader in=new BufferedReader(read); System.out.println("Enter the String"); str=in.readLine(); x=str.length(); for(i=x-1;i>=0;i--) { b=str.charAt(i); for(j=i;j<x;j++) System.out.print(b+" "); System.out.println(); } } } // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,i; char ch=0; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); for(y=0;y<x;y++) { for(i=0;i<=y;i++) { ch=st.charAt(i); System.out.print(ch+ " "); } System.out.println(); } } } Enter your word to print a pattern BLUEJ B BL BLU BLUE BLUEJ // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,i,j,z=0; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); 1 BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); for(y=0;y<x;y++) { for(j=y; j<x;j++) { ch=st.charAt(j); System.out.print(ch+ " "); } for (i=0;i<z;i++) { ch=st.charAt(i); System.out.print(ch+ " "); } z++; System.out.println(); } } } Enter your word to print a pattern BLUEJ BLUEJ LUEJB UEJBL EJBLU JBLUE // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,j; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); 2 st=in.readLine(); x=st.length(); for(y=x-1;y>=0;y--) { for(j=0;j<=y;j++) { ch=st.charAt(j); System.out.print(ch+ " "); } System.out.println(); } } } Enter your word to print a pattern BLUEJ BLUEJ BLUE BLU BL B // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,j,z; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); z=x-1; for(y=0;y<x;y++) { ch=st.charAt(z); for(j=0;j<=y;j++) System.out.print(ch+ " "); System.out.println(); z--; 3 } } } Enter your word to print a pattern BLUEJ J EE UUU LLLL BBBBB // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,j; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); for(y=0;y<x;y++) { for(j=y;j<x;j++) { ch=st.charAt(j); System.out.print(ch+ " "); } System.out.println(); } } } Enter your word to print a pattern BLUEJ BLUEJ LUEJ UEJ 4 EJ J Enter your word to print a pattern ABCDE ABCDE BCDE CDE DE E / A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x=65,y,j; char ch; System.out.println(" Given pattern is"); for(y=0;y<5;y++) { for(j=0;j<=y;j++) { ch=(char)(x); System.out.print(ch+ " "); x++; } System.out.println(); } } } Given pattern is A BC DEF GHIJ KLMNO // A program to display pattern import java.io.*; public class pattern 5 { public static void main(String arg[]) throws IOException { int x,y,j; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); for(y=0;y<x;y++) { for(j=y;j>=0;j--) { ch=st.charAt(y); System.out.print(ch+ " "); } System.out.println(); } } } Enter your word to print a pattern BLUEJ B LL UUU EEEE JJJJJ // A program to display pattern import java.io.*; public class pattern { public static void main(String arg[]) throws IOException { int x,y,i,j,z=0; char ch; String st; InputStreamReader read=new InputStreamReader(System.in); BufferedReader in = new BufferedReader(read); System.out.println("Enter your word to print a pattern"); st=in.readLine(); x=st.length(); 6 for(y=x-1;y>=0;y--) { for(j=0;j<=y;j++) { ch=st.charAt(j); System.out.print(ch+ " "); } for (i=0;i<z;i++) { ch=st.charAt(i); System.out.print(ch+ " "); } z++; System.out.println(); } } } Enter your word to print a pattern BLUEJ BLUEJ BLUEB BLUBL BLBLU BBLUE 7

Formatting page ...

Top Contributors
to this ResPaper
(answers/comments)


Chethan Magadi

(1)

Bob Bird

(1)

Jᴀɴɪᴄᴇ Cp

(1)

ResPaper Admins

(1)

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

Formatting page ...

 

  Print intermediate debugging step

Show debugging info


 

 

© 2010 - 2025 ResPaper. Terms of ServiceContact Us Advertise with us

 

numan90368 chat