Buat Faiz

mail@pastecode.io avatar
unknown
java
20 days ago
896 B
1
Indexable
Never
import java.util.Scanner;

public class Shortest {
    public static void main(String[] args) {
        Scanner userInput = new Scanner(System.in);

        System.out.print("Enter String #1: ");
        String s1 = userInput.nextLine();

        System.out.print("Enter String #2: ");
        String s2 = userInput.nextLine();

        System.out.print("Enter String #3: ");
        String s3 = userInput.nextLine();

        int shortest = s1.length();
        if(s2.length() < shortest){
            shortest = s2.length();
            if(s3.length() < shortest){
                System.out.println(s3);
            }
            else{
                System.out.println(s2);
            }
        }
        else if(s3.length() < shortest) {
            shortest = s3.length();
            System.out.println(s3);
        }
        else {
            System.out.println(s1);
        }
    }
}
Leave a Comment