Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Solution: which string is ahead in ABC?

package main

import "fmt"

func main() {
	var str1 string
	var str2 string
	fmt.Print("First string: ")
	fmt.Scan(&str1)
	fmt.Print("Second string: ")
	fmt.Scan(&str2)

	if str1 < str2 {
		fmt.Printf("The first string '%s' is ahead of '%s'\n", str1, str2)
	} else if str1 > str2 {
		fmt.Printf("The second string '%s' is ahead of '%s'\n", str2, str1)
	} else {
		fmt.Printf("The two string '%s' and '%s' are equal.\n", str2, str1)
	}
}