Advertisement
tsounakis

Slice_w3

Oct 19th, 2020
646
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.44 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "os"
  5.     "fmt"
  6.     "bufio"
  7.     "strconv"
  8.     "sort"
  9. )
  10.  
  11. func main() {
  12.     var num int
  13.     s := make([]int, 0, 3)
  14.     scanner := bufio.NewScanner(os.Stdin)
  15.     for scanner.Scan() {
  16.         if scanner.Text() == "X" {
  17.             break
  18.         } else {
  19.             num, _ = strconv.Atoi(scanner.Text())
  20.             s = append(s, num)
  21.             sort.Ints(s)
  22.         }
  23.     }
  24.     fmt.Printf("The slice is:\n")
  25.     for index, value := range s {
  26.         fmt.Printf("%d => %d\n", index, value)
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement