Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

smaller number possible instead of the maximum

  Asked By: Kiswar    Date: Jun 15    Category: Java    Views: 706

I need to change the below code so it will give me the smaller number possible
instead of the maximum. I need the Minimum number.

Can anyone help me where to modify or any suggestions please?

public class MaxVariablesDemo {

public static void main(String args[]) {

// integers

byte largestByte = Byte.MAX_VALUE;

short largestShort = Short.MAX_VALUE;

int largestInteger = Integer.MAX_VALUE;

long largestLong = Long.MAX_VALUE;

// real numbers

float largestFloat = Float.MAX_VALUE;

double largestDouble = Double.MAX_VALUE;

// other primitive types

char aChar = 'S';

boolean aBoolean = true;

// display them all

System.out.println("The largest byte value is " + largestByte);

System.out.println("The largest short value is " + largestShort);

System.out.println("The largest integer value is " + largestInteger);

System.out.println("The largest long value is " + largestLong);

System.out.println("The largest float value is " + largestFloat);

System.out.println("The largest double value is " + largestDouble);

if (Character.isUpperCase(aChar)) {

System.out.println("The character " + aChar + " is upper case.");

} else {

System.out.println("The character " + aChar + " is lower case.");


System.out.println("The value of aBoolean is " + aBoolean);





3 Answers Found

Answer #1    Answered By: Boyce Fischer     Answered On: Jun 15

I believe you need to change  the MAX_VALUE bits to MIN_VALUE that
will give  you the equivalent minimum values.

If you have installed the docs folder with the API in it (contains
all the standard Java classes in the SDK with their methods and
properties) you should find these properties. For example,
Integer.MIN_VALUE can be found on my computer at


Go to java.lang package, click on Integer link and you should find it.

Answer #2    Answered By: Stacy Cunningham     Answered On: Jun 15

I was stuck up in this problem and am unable to actually
start it. If anyone could help  me and solve this problem, i would be
Please reply with the code  as soon as possible.

A Queue class  built upon an array in circular fashion with overflow
and underflow exceptions.
A way of bending is to use the integer  % operator to bend the array
so that its two ends meet. We can do this by incrementing the array
index thus:


where a is an array and i is being used as an index into that array.

Example: suppose that a.length = 4. Consider the following table:

i i+1 (i+1)%4
0 1 1
1 2 2
2 3 3
3 4 0
4 5 1
5 6 2
6 7 3
7 8 0
8 9 1

So the result of assigning (i+1)%a.length would be an index
that "wraps around" to the beginning of the array once it reaches the
higher order end of the array. In the above example, the index
3 "increments" to the index 0.

It is easy to implement a queue with this idea using a front and rear
index. To insert, write the item into the array element whose index
is rear and then "increment" rear. To remove, return the value of the
array element whose index is front and "increment" front. The queue
is empty when front==rear. The queue is full when all the cells
contain data that has been enqueued.

In this problem, you are to write a circular integer Queue class
which is based on an the integer array as its principal state-holding
Name your class CirQueue.java.

enqueue integers at the rear of the queue and dequeue integers from
the front of the queue.

Include the following (non-static) constructors and methods in your

1) public  CirQueue(int length); // size sets the length of the
underlying array. The queue size is initialized to zero.

2) public CirQueue(); //the default constructor --sets the length of
the underlying array to 5. The queue size is initialized to zero.

3) public boolean full(); // true  if the queue occupies the whole
array, false otherwise.

4) public boolean empty(); // true if the queue is empty, false

5) public void  enqueue(int x) throws OverflowException; // if the
queue is full, it throws an OverflowEception, otherwise it inserts x
at the rear of the queue.

6) public int  dequeue() throws UnderflowException; // if it is empty,
it throws an UnderflowEception, otherwise it removes the element at
the front of the queue and returns its value.

7) public String toString(); // returns the state of the queue in
this exact form: f>0,1,2,3,4<r where the ints 1,2,3,4 have been
enqueued in that order. The letter f indicated the front of the
queue, the letter r indicates its rear. The empty queue must be
represented as f><r. (To get experience with recursion, you could
make this a recursive method -- but that is NOT a requirement).

8) public int size(); // returns the number  of elements currently in
the queue.
Write in only your CirQueue.java file. The Underflow and Overflow
exception classes for testing will be provided. You will, of course,
have to create these 2 exceptions in order for you to be able to
compile, run and test your design. (In case  you have read ahead and
are tempted to do so -- do NOT include the exceptions as inner

Each of the methods should be tested separately under full, empty and
non-full and non-empty states. You should test your queue with the
following class which should give  the indicated output:

public class UseCirQueue{

public static  void main(String[] args){
CirQueue q = new CirQueue();
for(int i = 0; i< 5;i++){
System.out.println(q+" size = "+q.size());
catch(OverflowException e){System.out.println(e);}
System.out.println("dequeue = "+ q.dequeue());
System.out.println(q+" size = "+q.size());
catch(UnderflowException e){System.out.println(e);}
for(int i = 0; i< 25;i++){
System.out.print(q +"--");
catch(OverflowException e){System.out.println(e);}
catch(UnderflowException e){System.out.println(e);}

f>0<r size = 1
f>0,1<r size = 2
f>0,1,2<r size = 3
f>0,1,2,3<r size = 4
f>0,1,2,3,4<r size = 5
dequeue = 0
f>1,2,3,4<r size = 4
dequeue = 1
f>2,3,4<r size = 3
dequeue = 2
f>3,4<r size = 2
dequeue = 3
f>4<r size = 1
dequeue = 4
f><r size = 0

A suggested development procedure (do not write and execute the whole
class at once): follow the same procedure that we suggested for the
Queue class.

You may find it easier to include a variable that keeps track of the
size of the queue rather than calculating the size.

Finally test your class with the given UseCirQueue class.

Answer #3    Answered By: Jimmie Ramirez     Answered On: Jun 15

If i am not wrong the doublelink queue suports all this.

Didn't find what you were looking for? Find more on smaller number possible instead of the maximum Or get search suggestion and latest updates.