#1
01.01.2013 um 18:04 UhrkA, wie das hier gelandet ist - das ist die Java-Lösung ;-)

Ruby :: Aufgabe #17 :: Lösung #1
Konsolenausgabe:
Texteingabe: Beispieltext
Textausgabe: BeIsPiElTeXt
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class GrossKleinSchreibung { public static void main(String[] args) throws IOException { System.out.println("Enter text: "); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String text = in.readLine(); System.out.println(manipulate(text)); } /** * makes all letters at position 2*k a lowerCase letter, all others upperCase. * All characters will be counted, but only letters will be modified. * @param text the text to manipulate * @return the manipulated String */ private static String manipulate(String text){ char[] chars = new char[text.length()]; //copy all chars as lowerCase into array text.toLowerCase().getChars(0, text.length(), chars, 0); //make every second letter a capital one for(int i=0; i<chars.length; i+=2) chars[i] = Character.toUpperCase(chars[i]); //rebuilt a String and return it return String.copyValueOf(chars); } }
Kommentare:
red18
Punkte: 260
5 Lösungen
1 Kommentare