Thursday, November 6, 2014

SOME VERY SIMPLE AND BASIC JAVA SOURCE CODES THAT I DEVELOPED. FEEL FREE TO POINT OUT ERRORS IF ANY.(PART-3)

SOURCE CODE #8
//A Simple java program to find the number of characters present in a String.
import java.util.*;
import java.io.*;
public class NumberOfCharactersInAString
{
public static void main(String args[]) throws IOException
{
int chara;
System.out.println("Enter a String");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
for(chara=0; chara {}
System.out.println("The total number of characters present in the String is " + chara);
}

}

OUTPUT FOR SOURCE CODE #8
Enter a String
Hemapriyagopal
The total number of characters present in the String is 14

SOURCE CODE #9
//How to input a string from the monitor and print the reverse of the string on the screen
import java.io.*;
public class StringReverse {
public static void main(String args[]) throws IOException
{
String name;
String revname;
System.out.println("Enter a string");
BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
name = br.readLine();
revname = new StringBuilder(name).reverse().toString();

System.out.println("The reversed string is " + revname);
}
}

OUTPUT FOR SOURCE CODE #9
Enter a string
Hemapriyagopal
The reversed string is lapogayirpameH

OUTPUT-2
Enter a string
as df
The reversed string is fd sa

No comments:

Post a Comment