ok

mail@pastecode.io avatar
unknown
java
a year ago
1.3 kB
0
Indexable
Never
import java.util.Scanner;
class UpperLowerCase {
    public String convertString(String words){
        String outputWord = "";
        
        for(int i = 0; i < words.length(); i++){
            char ch = words.charAt(i);
            //System.out.println("String A: "+ch);
            
            if (ch >= 'A' && ch <= 'Z') {
                outputWord = outputWord + Character.toLowerCase(ch);
            }
            else {
                outputWord = outputWord + Character.toUpperCase(ch);
            }
        }
        
        return outputWord;
    }
    public static void main(String[] args) {
        
        Scanner scA = new Scanner(System.in);
        System.out.print("Masukan Kalimat String A: ");
        String stringA = scA.nextLine(); 
        
        Scanner scB = new Scanner(System.in);
        System.out.print("Masukan Kalimat String B: ");
        String stringB = scB.nextLine();
        
        UpperLowerCase upperlowercase = new UpperLowerCase();
        
        String outputA = upperlowercase.convertString(stringA);
        String outputB = upperlowercase.convertString(stringB);
        
        System.out.print("String A = " +outputA+ "\n");
        System.out.println("String B = " +outputB);
    }
}