Unit 4 Getting started with objects Part2 Flashcards

(5 cards)

1
Q

What is the scanner class

A

import java.util.Scanner;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do Scanner objects work with?

A

-System.in
-So to create a Scanner object and connect it to the System.in object

Scanner keyboard= new Scanner (System.in);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a keyboard buffer

A

It is a temporary storage area.
-When you type something in the console and press enter, everything you typed plus the enter key \n is temporarily stored in memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is field width

A

-When you use a format specifier, like %d or %f you can add a number to control how many spaces wide the output should be

Eg: %6d
%=start of a format specifier
6=field width (6 spaces wide)
d=data type

Eg: if the number 9, then the output would be 5 spaces and then the number 9 because it is one digit so it takes up only one spot.

-if the number is longer java just expands the width it does not cut the number off

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens when you print with %f

A

When you print with %f java automatically fills in zeros to make exactly 6 digits after the decimal

eg:
double number=1278.92
system.out.printf(“the number is %f\n”, number);

output: the number is 1278.920000

How well did you know this?
1
Not at all
2
3
4
5
Perfectly