------------------------------------------------------------------------
Simple Java Program to understand String Manipulation
------------------------------------------------------------------------
*/
class VeryComplexHelloWorld{
public static void main(String args[]){
int i,j;
String helloworldmessage=" HelloWorld ";
String helloworld="H-E-L-L-O-W-O-R-L-D";
String[] listofchars;
String helloworldobtianedafterspliting="";
listofchars= helloworld.split("-");//splitting a string based on a delimiter
j=listofchars.length;//getting the length of an array
System.out.println("This Program does numerous manipulations to generate the Hello World message");
for(i=0;i
}
helloworldmessage=helloworldmessage.trim();//to remove leading and trailing spaces
helloworldmessage=helloworldmessage.toUpperCase();//Converting all characters of string to uppercase
if(helloworldmessage.equals(helloworldobtianedafterspliting)){//to compare two strings
System.out.println(helloworldmessage);
}
}
}
/*
------------------------------------------------------------------------
Output of Complex Hello World
------------------------------------------------------------------------
C:\Users\flower\Documents\javaprogs>javac VeryComplexHelloWorld.java
C:\Users\flower\Documents\javaprogs>java VeryComplexHelloWorld
This Program does numerous manipulations to generate the Hello World message
HELLOWORLD
------------------------------------------------------------------------
*/
No comments:
Post a Comment