Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Récupérer les informations saisies au clavier
NDONGO TONUX SAMB
NDONGO TONUX SAMB

Posted on

     

Récupérer les informations saisies au clavier

Dans ce tutoriel, nous allons voir comment accepter les entrées de l'utilisateur. Nous utilisons la classe Scanner pour obtenir l'entrée. Dans l'exemple ci-dessous, nous recevons une entrée de type String, integer et float. Pour cela, nous utilisons les méthodes suivantes :

  • 1) public String nextLine() : Pour obtenir l'entrée String
  • 2) public int nextInt() : Pour l'entrée d'un nombre entier
  • 3) public float nextFloat() : Pour l'entrée des flottants
importjava.util.Scanner;classGetInputData{publicstaticvoidmain(Stringargs[]){intnum;floatfnum;Stringstr;Scannerin=newScanner(System.in);//Obtenir la chaîne d'entréeSystem.out.println("Saisir une chaine: ");str=in.nextLine();System.out.println("La chaine saisie est: "+str);//Get input IntegerSystem.out.println("Saisir un entier: ");num=in.nextInt();System.out.println("L'entier saisi est: "+num);//Get input float numberSystem.out.println("Entrez un numéro de flottant: ");fnum=in.nextFloat();System.out.println("Le numéro de flottant est : "+fnum);}}
Enter fullscreen modeExit fullscreen mode

Sortie sur la console.

Saisir une chaine: AstouLa chaine saisie est: AstouSaisir un entier: 313L'entier saisi est: 313Entrez un numéro de flottant: 12.56Le numéro de flottant est: 12.56
Enter fullscreen modeExit fullscreen mode

Sans plus tardé, on va maintenant voir comment faire des conditions avec Java.

prochain chapitre:les conditions

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

https://www.tonuxcorp.dev I have always been fascinated by the world of IT development, and I have oriented my studies in this field and have been evolving for many years as a professional developer
  • Education
    Polytechnique ESP Dakar, Senegal
  • Work
    Developper
  • Joined

More fromNDONGO TONUX SAMB

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp