SlideServe
Menu
Préférences
© SlideServe · v2026

Java Basics: Creating Objects and Using DecimalFormat

christopherclark avatar
5 diapositives · 84 Views · Jan 02, 2020

Learn how to create objects in Java with examples including Scanner, DecimalFormat, Random. Explore formatting decimal numbers with DecimalFormat class. Practice generating random numbers and calculating averages.

Java Basics: Creating Objects and Using DecimalFormat - slide 1
01 / 5Java Basics: Creating Objects and Using DecimalFormat
1 / 17

Télécharger la présentation

Java Basics: Creating Objects and Using DecimalFormat
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Creating Objects Pepper

  2. Objects You Already Create • Scanner: • Import java.util.Scanner; • Scanner scn = new Scanner(System.in); • Pictures: • import javalib.worldimages.*; • import java.awt.Color; • WorldImagemyCircle = AImage.makeCircle(50,Color.blue, Mode.filled); • Color bluegrey = new Color(23,32,43);

  3. New Object - DecimalFormat • Knows how to format a decimal number • Library: java.text.DecimalFormat • Import java.text.DecimalFormat; • Tell it your format method when you create it • DecimalFormatmyf = new DecimalFormat("0.0#"); • Ask your formatter to format any number • myf.format(3.555); • myf.format(x); • Many formats: http://pic.dhe.ibm.com/infocenter/adiehelp/v5r1m1/index.jsp?topic=%2Fcom.sun.api.doc%2Fjava%2Ftext%2FDecimalFormat.html

  4. New Object - Random • Knows how to create a random number • Library: java.util.Random • import java.util.Random • Create a random maker guy • Random r = new Random(); • Ask him to give you a number out of # choices: • nextInt(6); returns 0 – 5 • nextInt(13); returns 0-12

  5. Exercise • Generate 2 dice values using Random • Print the two dice values • Divide by 2 to get the average • Print the average with only 1 decimal place