Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 2 out of 14 pages
Exam (elaborations)

CMSC131 REVIEW QUESTIONS WITH VERIFIED ANSWERS

Document preview thumbnail
Preview 2 out of 14 pages

CMSC131 REVIEW QUESTIONS WITH VERIFIED ANSWERS

Content preview

CMSC131 REVIEW QUESTIONS WITH VERIFIED
ANSWERS


Why are there 8 different numeric types in java? - Answers - Because java is a
restrictive language: it requires that the bit count is noted and known. Different types
have different bit counts, so it shows the size.

How would you write an int and float constants? - Answers - int i= number;
float f= number;

How would declare a variable with initialization versus without? - Answers - with:
int i= 2;

without:
int i;

What is the order of precedence? - Answers - 1. parentheses/brackets
2. cast/new objects
3. multiplication/division
4. addition/subtraction
5. relational (instanceof)
6. equality
7. and (&&)
8. or (||)
9. assignment

How would you print "Hello World" onto one line? - Answers - System.out.print("Hello ");
System.out.print("World");

How would you print "Hello World" onto 2 separate lines? - Answers -
System.out.println("Hello");
System.out.println("World");

What is the difference between system.out.println(); and system.out.print(); - Answers -
println prints the messages on different lines while print prints the messages on the
same line

How can you convert an int to a char? - Answers - Declaration
1. set the char to a variable
2. set an int variable to that char variable

NumericValue
1. create an int variable that is the Character.getNumericValue(charVariable);

, String Value of
1. Create an int variable
2. assign it to Integer.parseint(String.valueOf(c));

How do you cast a float to an int? - Answers - Math.round
1. use Math.round();

Type Casting
1. int value= (int) 3.10f//

How do convert an int to a char? - Answers - Type Casting
int a=65;
char c=(char)a;

Character.forDigit()
int a=1;
char c= Character.forDigit(a);

What is a widening type conversion? - Answers - When you are casting a type object to
a greater primitive data type:

-byte to short, int, long, float, or double

-short to int, long, float, or double

-char to int, long, float, or double

-int to long, float, or double

-long to float or double

-float to double

What is a narrowing type conversion? - Answers - When you are going from a larger
primitive data type to a smaller, meaning you must cast the type/round it.

How would you declare a char variable equal to a? - Answers - char ch= 'a'; //needs
single quotes

How would you generate a random number? - Answers - Math.random(); //returns
double between 0.0 and 1.0

Random class:
Random rand= new Random ();
int r= rand.nextInt(100); //number 1 to 99

Document information

Uploaded on
July 10, 2026
Number of pages
14
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.
GEEKA
3.8
(361)
Sold
2137
Followers
1449
Items
58515
Last sold
2 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