Computer Science, asked by 62rehankhan29, 9 months ago

Write a program to input a sentence and display the words in odd position in capital case and the

words in even position in small case.

Example INPUT: god is great

OUTPUT: GOD is GREAT
urgrnt plz pz plz​

Answers

Answered by Oreki
2

import java.util.Scanner;

public class StringManipulation {

public static void main(String[ ] args) {

// Accepting sentence and converting it into a String array.

System.out.print("Enter a Sentence - ");

String[ ] sentence = new Scanner(System.in).nextLine( ).split(" ");

// Printing even positioned words in lower and odd ones to upper case.

for (int i = 0; i < sentence.length; i++)

System.out.printf("%s ", (i % 2 = = 0) ? sentence[i].toLowerCase( ) : sentence[i].toUpperCase( ));

}

}

Similar questions