Conversion of string to Capital letters

Problem: Write a program that reads one line of text and then prints it with all its letters capitalized.

Hello all,

I have solved the problem very simple way. But i need more ways. can anybody help me to do this others ways.

Here is my code and it works fine.

public class CapitalizedLetters

{

static String input;

public static void main(String args[])

{

input = "Ripon Al Wasim";

System.out.println(getCapital(input));

}

static String getCapital(String s)

{

//char c[] = s.charArray();

s = input;

String ss = input.toUpperCase();

return ss;

}

}//end class CapitalizedLetters

Thanking u,

Ripon

[728 byte] By [riponc007a] at [2007-9-29 0:52:12]
# 1

Does using Arrays.sort(...) count as implementing a sorting routine?

hint: you are on the right track using char[] c = s.charArray();

Try doing the following:

char f = 'a';

for (int i = 0; i < 30; i++) {

f = f + 1;

System.out.print("" + f + " ");

}

rkippena at 2007-7-13 3:17:45 > top of Java-index,Other Topics,Algorithms...
# 2

1) you could retrieve the input String using command line argument

2) you could retrieve the input String using Swing GUI

3) you could use a for loop to turn each individual char to uppercase and then concatenate

4) you could use the StringBuffer class to do it

Hope this helps!

ArtVandelaya at 2007-7-13 3:17:45 > top of Java-index,Other Topics,Algorithms...
# 3
Take that char array and add ((int)'A' - (int)'a') to each of the letters. That will convert them using their values. BTW I do not think you even need the casts but I was not sure and overcasting does not hurt anything so far as I know.
gtg833ba at 2007-7-13 3:17:45 > top of Java-index,Other Topics,Algorithms...
# 4

well as there is a method already 'stringID.toUpperCase()' why write a method?

Manually, its not so very hard - - - > psuedo-code

1. for loop(Condition 0=>number of chars) // cycle through the chars 1 at a time

2. int anInt = (cast to int) the next char

3. if('anInt' > 96 AND anInt < 123) // ascii lower case chars

4. (then do) anInt = anInt - 32 // ascii 'a' = 97 - - - ascii 'A' = 65

5. the next char = (cast to char) anInt

6. end 1 iteration of the loop

as for getting a string of chars to do this ... OK;-

String input = javax.swing.JOptionPane.showInputDialog("Enter a sentence for processing: ");

Sscottiesa at 2007-7-13 3:17:45 > top of Java-index,Other Topics,Algorithms...