“Golang -Scanner” Code-Antworten

Golang -Scanner

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	fmt.Print("What is your name ? ")
	nama := bufio.NewScanner(os.Stdin)
	nama.Scan()

	fmt.Print("How old are you ? ")
	age := bufio.NewScanner(os.Stdin)
	age.Scan()

	if umur := age.Text(); umur < "20" {
		fmt.Printf("Sorry %s your age is under 20 old age \n", nama.Text())
		return
	}

	fmt.Printf("Congrats %s your age is greater than 20 old age \n", nama.Text())
}
Restu Wahyu Saputra

Golang -Scanner

func main() {

    // include space this is not throw error
	fmt.Print("Masukan Nama Anda ?")
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	fmt.Println(scanner)

    // same with scanner, but if value include space this is throw error
	var name string
	fmt.Print("Masukan Nama Anda ? ")
	fmt.Scan(os.Stdin, &name)

	fmt.Println(name)
}
Restu Wahyu Saputra

Ähnliche Antworten wie “Golang -Scanner”

Fragen ähnlich wie “Golang -Scanner”

Weitere verwandte Antworten zu “Golang -Scanner” auf Go

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen