• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 6 pages
Exam (elaborations)

Dsa Quiz 1 With Complete Solutions

Document preview thumbnail
Preview 2 out of 6 pages

DSA QUIZ 1 WITH COMPLETE SOLUTIONS

Content preview

DSA QUIZ 1 WITH COMPLETE
SOLUTIONS

main method - Correct Answers -public static void main(String[] args)

How Java works - Correct Answers --You write Xyz.java files
-Your file, Xyz.java, must define the class Xyz
-The compiler writes Xyz.class files at compile time
-Java (JVM) reads Xyz.class

random - Correct Answers -*Random( ) Creates a random number generator.
Random random = new Random()
*int die = random.nextInt( int number ); 0 to number is max but exclusive

Scanner - Correct Answers -Scanner scan = new Scanner( System.in );

scanner methods - Correct Answers -nextDataType( ) returns the next token in the input
stream as a dataType. dataType can be byte, int, short, long, float, double, or boolean
next( ) returns the next token(word) in the input stream as a String nextLine( ) returns
the remainder of the line as a String

*come after new Scanner() and prompt as scannername.next...
** can't do nextChar so read as String and use atChar(0)

Commenting - Correct Answers -// beginning of one line
/* beginning of multiple */ end of multiple
/** special comment that can be turned into documentation */

DataType parts - Correct Answers -Domain
-what values can be stored?
-what is the range of values?
-what is a legal value? (bounds)
-determines how much memory to reserve (size)

Operations
-what can you do?
-what can't you do?
-determines operations

Static Typing - Correct Answers --All variables must be declared with a type before they
are used

, -A variable cannot change types! (static = does not change)
-Data type determines allowed operations

Primitive Data Types - Correct Answers -Whole number integers Differ in size (number
of digits):
byte
short
int
long

Decimal numbers Differ in precision (number of digits) :
float
double

boolean: True / False
char only: A single character

Names - Correct Answers -Variable names are case-sensitive:
Donkey != donkey

Classes are TitleCase
Variables/methods are camelCase

identifiers/Keywords - Correct Answers --Made up by Java
-Must start with a letter and contain only letters, digits, and underscores
-Case sensitive

final keyword - Correct Answers -variable's literal cannot be changed

Every expression has - Correct Answers -data type
value

right (value) must fit in left (data type)

underscores - Correct Answers -use as commas in numbers

When numbers do not fit allocated memory space - Correct Answers -data can be lost
casting makes sure data doesn't get lost

rounding when double to int - Correct Answers -down

char - Correct Answers -single letter
treated as int and can do operation with number equivalent

Control Structures - Correct Answers -Sequential
Branching: break return

Document information

Uploaded on
March 26, 2026
Number of pages
6
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
millyphilip
3.7
(560)
Sold
2991
Followers
1963
Items
46798
Last sold
4 days ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions