0% found this document useful (0 votes)
108 views1 page

Java Assignment Question

This document contains questions about Java concepts and programming exercises. It asks about Java's character type, using short-circuit AND to prevent divide-by-zero errors, inner classes with examples, namespaces and why they are important in Java, accessing members of packages between packages with examples, using Math.random() to generate random numbers between 0 and 1 and testing it, creating a max() method to return the largest of three integers using if-else-if and nested if statements, and listing and illustrating different String methods with examples.

Uploaded by

Mahalakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
108 views1 page

Java Assignment Question

This document contains questions about Java concepts and programming exercises. It asks about Java's character type, using short-circuit AND to prevent divide-by-zero errors, inner classes with examples, namespaces and why they are important in Java, accessing members of packages between packages with examples, using Math.random() to generate random numbers between 0 and 1 and testing it, creating a max() method to return the largest of three integers using if-else-if and nested if statements, and listing and illustrating different String methods with examples.

Uploaded by

Mahalakshmi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

What is Java’s character type, and how does it differ from the character type used by
some other programming languages?

2. Show how a short-circuit AND can be used to prevent a divide-by-zero error.


3. What is inner class? Explain with suitable example.
4. What is a namespace? Why is it important that Java allows you to partition the
namespace?
5. Explain the two ways that the members of a package can be accessed by other Packages
with suitable example

6. Math.random( ) is a method in the Java library that computes a random double value
between 0 and 1. For example, the statement double x = Math.random(); assigns to the
variable x a random double between 0 and 1. Write a program that tests how well
Math.random( ) works. More precisely, write a program that calls Math.random( )
1,000 times to create 1,000 values, keeping track of how many of them are greater than
0.5, and then prints out the result. Your program should theoretically print out a number
very close to 500.

7. Create a method max( ) that has three integer parameters x, y, and z and it returns the
largest of the three. Do it two ways: once using an if-else-if ladder and once using nested
if statements.
8. List and illustrate different String Methods with examples.

You might also like