Vishal Vishal - 1 year ago 99
Java Question

Converting Lowercase array to Uppercase without using toUpperCase()

First off this is a homework assignment and I'm looking for some help because I'm stuck. I've been working on this for hours and couldn't figure it out. I'm trying to take a user input as a string and store it as a char array and output the characters in all Uppercase without using the


I've written the code so far and my plan is to create two arrays which contains the lowercase alphabet and the uppercase alphabet and create and for loop and inside that an if statement which replaces the characters int the char array and outputs them in Uppercase. But I can't figure out how to replace the characters. This is what I got so far:

import java.util.Scanner;
class Q4{
public static void main(String []args){
Scanner input = new Scanner(;
System.out.print("Enter a String: ");
String s = input.nextLine();
String s1 = s.toLowerCase();
char[] s2 = s1.toCharArray(); //Converts the String into a char Array

char LowerAlp[] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char UpperAlp[] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

for(int i=0; i<s2.length; i++){
//Here is the problem


Answer Source

I don't think you need the arrays:

for(int i = 0; i <s2.length; ++i)
    if('a' <= s2[i] && s2[i] <= 'z')
        s2[i] += 'A' - 'a';