Write a java program so that odd position char will be in uppercase & even will be lowercase


Program
import java.util.Scanner; public class UPLC{ public static void main(String []args){ Scanner sc = new Scanner(System.in); String str = sc.next(); int strlen = str.length(); for(int i = 0 ; i < str.length(); i++){ char ch = str.charAt(i); if(!(ch >= 'a' && ch <='z' || ch >= 'A' && ch <='Z' )){ System.out.println(str+ " is an invalid input"); return; } } if(strlen >= 5 && strlen <= 20){ StringBuffer updateString = new StringBuffer(); char[] charArr = str.toCharArray(); for(int i = 0 ; i < charArr.length; i++){ char ch = charArr[i]; if(i % 2 != 0){ ch = Character.toUpperCase(ch); } updateString.append(ch); } System.out.println(updateString.toString()); } else { System.out.println(str+ " is an invalid Length"); } } }
Input
Output