import "fmt" func main() { var str string fmt.Print("Enter a string: ") // scans text read from standard input, storing them space-separated // for example we can read Mahmood from input, but not Mahmood Ramzani fmt.Scanln(&str) fmt.Printf("String Value : %v\n",str) var str1,str2 string fmt.Print("Enter two string: ") fmt.Scanln(&str1,&str2) fmt.Printf("String Value1 : %v\n",str1) fmt.Printf("String Value1 : %v\n",str2) }
import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text :") str, _ := reader.ReadString('\n') fmt.Println(str) fmt.Print("Enter a number : ") str, _ = reader.ReadString('\n') // trim space trimmedStr := strings.TrimSpace(str) // convert string to int number, err := strconv.ParseInt(trimmedStr, 10, 32) if err != nil { fmt.Println(err) } else { fmt.Println(number) } }