Home:ALL Converter>Struggling with uppercase or lowercase

Struggling with uppercase or lowercase

Ask Time:2013-11-17T06:11:36         Author:Snorrarcisco

Json Formatter

import java.util.Scanner;

public class ShoutandWhisper {

    public static void main(String[] args) 
    {
        //defining the variables
        String word, word1;
        //Input
        Scanner kb = new Scanner(System.in);
        System.out.print("Give me a word that has 7 letters > ");
        word = kb.nextLine();
        word1 = word.toUpperCase();
        System.out.println("I shout " + word1 + " when I'm excited, but i whisper " + word + " when i can't disturb the neigbours.");
        char achar = word.charAt(0);
        char bchar = word.charAt(1);
        char cchar = word.charAt(2);
        char dchar = word.charAt(3);
        char echar = word.charAt(4);
        char fchar = word.charAt(5);
        char gchar = word.charAt(6);
        //Changing to uppercase
        char Bchar = Character.toUpperCase(bchar);
        char Dchar = Character.toUpperCase(dchar);
        char Fchar = Character.toUpperCase(fchar);
        System.out.println("And the mixed up word is " + achar+Bchar+cchar+Dchar+echar+Fchar+gchar);
    }

}

Now the code does work but is there a shorter way to produce alternating Uppercase or Lowercase outputs without using a For counter? rewriting the entire "newer" variables is an accident waiting to happen. Especially with me.

I tried to force it as i was selecting the letter by letter and I couldn't do it.

Main goal is to either Shout or whisper and then sort the word using alternating Uppercases from second letter.

Author:Snorrarcisco,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/20024574/struggling-with-uppercase-or-lowercase
Alexis C. :

You can convert the word to an array of char and use a for loop to alternate upper and lower case :\n\nchar [] c = word.toLowerCase().toCharArray();\n\nfor(int i = 1; i < c.length; i = i+2){\n c[i] = Character.toUpperCase(c[i]);\n}\n\n\nThen just construct a new String with this char array (using the constructor String(char[] value)) and you'll get your word.",
2013-11-16T22:16:07
yy