[go: up one dir, main page]

0% found this document useful (0 votes)
7 views9 pages

Library Classes

Tt

Uploaded by

anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Library Classes

Tt

Uploaded by

anjum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
VIII. Unsolved Java Programs on Character Manipulations: Q.1 Write a program in Java to input a character. Find ard display the next 10* character in the ASCII table, . import java.util"; ee public class Dis_Char { public static void main(String argst ]) { Scanner in = new Scanner(System in); System.out.print("Enter a character: "); char ch = in.next( ).charAt(0); char nextCh = (char)(ch + 10); System.out.printin(‘Tenth character from" + ch +" is” + nextCh); } Q.2 Write a program in Java to generate all the alternate letters in the range of letters from A to Z. Prog. public class Dis_Letters { public static void main(String args[ }) { char ch; for (ch = ‘A’; ch <='Z'; ch = (char)(ch + 2)) System.out println(ch); to input a set of 20 eters: Convert each 8 wore an dy tember of vowels a rary seats presenta the wet of give etter 7 rog. import java util public class Dis Letters ( public static vod main(String anes ( Scanner in = new Scanner{System in); System.out printin( Enter any 20 eters"; int ve =0,c¢=0; char ch; for (int i= 0;1< 20;i44) ( chs in.net().char At); a Chaacetot pees “te [| ch=='' || ch. 1 System.out printin("Number of Vowels =" vc) System out printin(’Number of Consonants ="-+ ec); 1 ) QA Write a program in Java to accept an integer number N such that 0.< Ne 27, Display the corresponding letter of the English alphabet (ie, the letter at position N). [Hint: IFN =1 then display A] Prog. import java.util’ public class Dis_Letter 1 public static void main(String args{ I) { Scanner in = new Seanner(System in); int char ch; System out print"Enter an integer: "), n= innextint(); if(n> 0 &&n<27) ( ch= (char)in + 64); , Sssemout print Comesponding ter =" else System.out printin(‘Enter a number in the range 1 to 26"); ch); 4 PORTA np hy Ola ett es treed. ASC er from ten vale of atcha I ale of second es sample Input: -D rn the heybonn. Find the Piaply the folowing mesaagee 's toss than the second. acter is more than the fis. ee poate static void main(String args} Sexe in = ew Scart in char cht, ch2; System out print(Enter first character") chi = innnext( )charAt(0); hs System.outprint(Enter second character") ch2 = innext{ )charAt(0); = (int)ehl - (int)ch2; a>0) System out printin( ‘Second characteris smaller); seit (d<0) _Spsemoutpintn Fist chases smal), System out printInBoth the characters are same’); ! ! (Q6 Wiitea program toinput letter Find its ASCH code. Reverse the SCL code and display the equivalent character. Sample Input: ¥ Sample Output: ASCII Code = 89 Reverse the code = 98 Equivalent charater:b Frog. impor java tl; public class ASCIIReverse 1 public static void main(String args) 1 Scanner in = new Scanner(System.in); inta,r d; char cht; System out print(‘Enter a letter"); chr = inanext{)charAt(0) a= (intchr; System.out printin(“ASCI Code =" +a) while (a >0) ' de a% 10 ' sstem out printin( ‘Reversed Code =" +9 en eer ' ‘ Q7 Write a program to input vowels in lowercase and display their Asc Prog. import java.util*; to 1 public static void main(String args 1) i ‘Scanner in = new Scanner(System.in); inta; char ch; System out printin(Enter vowels in lowercase’ ‘System out printin("Vowels ASCII Values"); for(a=l; a<-5;at+) ch= innext().charAt(, System outprintin(ch +"\t\t" + (it)ch); ) 1 ) 8 Writea program to input a set of any 10 integer numbers. Find the sum and product ofthe numbers. Join the sum and product to form a singe number. Display the concatenated number. {Hint Let sum=245 and product = 1346 then the number afte joining sum and product will be 2451346] Prog. import java.util"; public class ValueConcat 1 public static void main(String args{ ]) { Scanner in = new Scanner(System in); System outprintin("Enter any 10 integers") Jong sum ens inti, n, String st; for (i=0;1<10;i++) sum +=n; prod *= n, ) t= Long toStingteum) «an 85 Long parseLongiaty, M8 String pred, System.out printine’Sum =, sum) System.out PHNIN Product a", System.out print ; HN "Concatenated Number « +n), 1 ven t0'8/and lowercase letters frome ‘alas ‘ ve 8 Per the user's choice y letters from 210 and Ente 2” to display lowercase letter fae oo import java.util; Gates ' Public static void main(String args} { Scanner in =new Scanner(System.in) int ch, 0, i System out print("Enter your choice"; ch=in.nextint( ‘switch (ch) { case 1: for (i= 90;i > 64;i--) { char cht = (char System.out print(chr); System.out print(""); cH //Print 10 characters per line if(c==10) ( System.out printin(); c=0; ) ) break; % “for i= 971 <12i48) i char che = (char); ‘System out print(che); ies 1) "system, coutpprintin( i no ! 1 break: default system out incorrect Choice!" u.printin( 1 ) ! i {0.10 Write a menu driven program 1° display {i fist five uppercase letters 2 (ast five lowercase letters as er the user's choice. oes display uppercase letters and 2't0 display lowercase let Prog. import java.util; public class Menu t public static void main(String args! }) Scanner in = new Scanner(System.in); inti, ch; ‘System out printin( System.out printin("Enter System-out print("Enter your choice: ch= innextint(); switch (ch) { case1: for i= 61 <= 8144) oe out printin((char)i); case 2: foe (i= 81 co 122; be) cisemeoutprinin( chan default: I Enter 'I'to display uppercase letters"); °2' to display lowercase letters"); 5 1 Using switch case st Oo ane ment wrt menu driven program perform {@) Togenerate and print the letter from AtoZ along with their Unicode. Letters Unicode A 6 66 z 90 (0) To generate and print the eters from zo a along with their Unicode Letters Unicode : z m2 y 1m “ae Prog. // To display the pattem as per the users choice rt java.util"; public class Display Pattern { public static void main(String args{ |) { Scanner in=new Scanner(System.in); inti char ch; String str; System.outprintin(Enter 1 to display uppercase letters and the "Unicode") hk Systemout printin(‘Enter 2 to display lowercase leters and the “Unicode"); System.out printin(Enter your choice kein.nextint(); switeh(k) \e\t" + (inch); ( System outprintin(ch + Gry 5 printin(Letters\t\ Unicode) forich='2;ch>='a'sch—-) ' System out printinch + 1 break: yeh + (inti em outpintin(Eatered WOMB choice!) 1 1 ! Q.12 Write a program in av (@) ABCDE ABCD ABC AB A Prog, publicclass Pattern 1 to display the following patterns: ( public static void main(String argsf }) ( iol) Sytemoue pina 1 ‘System.out printin( ); pbs vol minting) inti, j, p=65; fork <5; i64) forge uj =1;i--) Li) <=isjt+) { System out print((char)p); pHs ) ket; System.out printin( ); } ! ! (@) ASBYCDE ASBYC'D" ABYC AB a” og. public class Pattern public static void main(String args{ ) Ve a for(i = 69;i>= 65;i--) ' for (j = 65; j <= i; j++) ‘ ‘System.out print((char)j + "*"); System.out printin( ;

You might also like