double | float

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Reading and writing floating point numbers

scanner method to read in a float is : nextFloat() Scanner method to read in a double: nextDouble()

Which of the following format specifiers rounds the number to two decimal digits?

%.2f

How many bytes in a float?

4

Double is the default value for ?

Decimals

What type should you use when precise values are needed working with money?

Do not use double or float - use BigDecimal

how to round to 3 digits after the decimal point

%.3f

format specifier in format string is ?

%f

Write a program that reads in 2 numbers from a user using a double and float, then print with a format specifier restrict to 3 digits after decimal .

import java.util.Scanner; public class Name { public static void main (String[] args) { Scanner input = new Scanner (System.in); System,out,print("Number1: "); double number1 = input.nextDouble (); System.out.print("Number2: "); float number2 = input.nextFloat (); System.out.printf ("number1: %.3f%n", number1); System.out.printf ("number2: %.3f%n", number2); } }

You have an instance of Scanner that was defined like this: Scanner input = new Scanner(System.in); Which method call can you use to read in a floating point number from the user?

input.nextFloat();

float is used to save

memory

What happens if you execute the following statement: double number = 1.1 / 0;

number gets assigned infinity

The size of float is _______ bytes

4

The size of double is ______ bytes

8

how many bytes in a double?

8


Ensembles d'études connexes

Chapter 10-16 True or False (Pharmacology)

View Set

Business Law II Midterm Chp 32-35 48-49

View Set

Ch 18/19: Cell- Division Cycle /Apoptosis/ Mitosis

View Set

Cardiac Output, Venous Return, and Their Regulation

View Set

PSYC&100 General Psychology: Chapter 16

View Set

Church History Trimester 1 Review Ch. 1

View Set