Professional Documents
Culture Documents
faq:
Method Signature:
syntax:
Note:
Enum<E> class.
----------------------------------------------------
faq:
Method Signature:
public int length();
syntax:
-----------------------------------------------------
faq:
Method Signature:
syntax:
char ch = str.charAt(index);
---------------------------------------------------------
faq:
Interchange and every character from Keyword input will have its
UpperCase Letters : 65 to 90
Numbers(0 to 9) : 48 to 57
Ex : DemoString2.java
package p1;
public class DemoString2 {
public static void main(String[] args) {
System.out.println("====UpperCase Letters====");
for(int i=65;i<=90;i++)
{
char ch = (char)i;//ASCII value into char
System.out.print(ch+" ");
}//end of loop
System.out.println("\n====LowerCase Letters===");
for(int i=97;i<=122;i++)
{
char ch = (char)i;//ASCII value into char
System.out.print(ch+" ");
}
System.out.println("\n===Numbes(0-9)===");
for(int i=48;i<=57;i++)
{
char ch = (char)i; //ASCII value into char
System.out.print(ch+" ");
}
}
}
o/p:
====UpperCase Letters====
ABCDEFGHIJKLMNOPQRSTUVWXYZ
====LowerCase Letters===
abcdefghijklmnopqrstuvwxyz
===Numbes(0-9)===
0123456789
=====================================================
Number of Consonents
Program : DemoString3.java
package p1;
import java.util.*;
public class DemoString3 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the String:");
String str = s.nextLine();
int len = str.length();
System.out.println("===Normal String===");
System.out.println(str.toString());
System.out.println("length:"+len);
int vcount=0,ccount=0;
for(int i=0;i<=len-1;i++)
{
char ch = str.charAt(i);//Char based on index
switch(ch)
{
case 'a':
case 'A':vcount++;
break;
case 'e':
case 'E':vcount++;
break;
case 'i':
case 'I':vcount++;
break;
case 'o':
case 'O':vcount++;
break;
case 'u':
case 'U':vcount++;
break;
}//end of switch
int k = (int)ch;//Char into ASCII
if((k>=65 && k<=90) || (k>=97 && k<=122))
{
ccount++;
}
}//end of loop
System.out.println("Number of Vowels:"+vcount);
System.out.println
("Number of Consonents:"+(ccount-vcount));
s.close();
}
}
o/p:
===Normal String===
length:27
Number of Vowels:6
Number of Consonents:11
=========================================================
Assignment:
Number of vowels
Number of Consonents
Number of Numbers
Sum of Numbers
Number of others
Vowels : 12
Consonents : 21
Nubers : 1 7 2 0 2 1 9 0
sum = 22
Others : 10
========================================================
faq:
on index values.
Method Signature:
Program : DemoString4.java
package p1;
public class DemoString4 {
public static void main(String[] args) {
String str = "java language";
String s1 = str.substring(5);
//SubString taken from index 4
System.out.println("s1:"+s1.toString());
String s2 = str.substring(2,8);
//substring taken from index 2 to 7
System.out.println("s2:"+s2.toString());
}
}
====================================================
Assignment:
Year of Joining
CollCode
BranchCode
No
==========================================================