2016-10-11

posted Oct 11, 2016, 6:11 AM by Samuel Konstantinovich   [ updated Oct 13, 2016, 10:38 PM ]
The myUpper static method from the last lecture:

public class Demo
{
  public static boolean isLower(char c){
    return c >= 'a' && c <= 'z'; 
  }

  public static String myUpper(String s){
    String ans = "";
    int i = 0;
    while(i < s.length()){
      char temp = s.charAt(i);
      if(isLower(temp)){
       ans += (char)(temp - 'a' + 'A');
      }else{
       ans += temp;
      }
      i++;
    }
    return ans;
  }
  
  public static void main(String[] args)
  {
    if(args.length > 0){
System.out.println( myUpper(args[0]));
    }
  }
}

Comments