Question

JAVA HELP! Question: Write a Java console application that investigates how well Java handles large integers....

JAVA HELP!

Question:

Write a Java console application that investigates how well Java handles large integers. Write two loops that iterate from 0 through 35. Before each loop, set an integer variable (IV) to 1. Within each loop, print the loop count and the value of IV formatted in two columns. Within the first loop, multiply IV by 2. Within the second loop, multiply IV by the appropriate StrictMath method. The second loop will not complete since there will eventually be an integer overflow.

Note: I am a beginner at Java, so please make it simple. Thanks.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.lang.*;
public class LargeIntegers {
public static void main (String args[]) {
int VI =1;
for(int i =0;i<30;i++)
{
VI = VI*2;
int count = i+1;
System.out.println("loop count value is "+ count + " and value of IV " + VI);
}


for(int j =0;j<30;j++){

/*int count = j+1;
Double D = StrictMath.pow(2 , j+1);
int V = Integer.valueOf(D.intValue());
System.out.println("loop count values is "+ count + " and value of IV " + V );*/

for(int j =0;j<30;j++){
       System.out.println("loop count"+ j+1 + " value of IV " + Math.multiplyExact(VI,2));
       }
}
}
}

Output:

loop count value is 1 and value of IV 2
loop count value is 2 and value of IV 4
loop count value is 3 and value of IV 8
loop count value is 4 and value of IV 16
loop count value is 5 and value of IV 32
loop count value is 6 and value of IV 64
loop count value is 7 and value of IV 128
loop count value is 8 and value of IV 256
loop count value is 9 and value of IV 512
loop count value is 10 and value of IV 1024
loop count value is 11 and value of IV 2048
loop count value is 12 and value of IV 4096
loop count value is 13 and value of IV 8192
loop count value is 14 and value of IV 16384
loop count value is 15 and value of IV 32768
loop count value is 16 and value of IV 65536
loop count value is 17 and value of IV 131072
loop count value is 18 and value of IV 262144
loop count value is 19 and value of IV 524288
loop count value is 20 and value of IV 1048576
loop count value is 21 and value of IV 2097152
loop count value is 22 and value of IV 4194304
loop count value is 23 and value of IV 8388608
loop count value is 24 and value of IV 16777216
loop count value is 25 and value of IV 33554432
loop count value is 26 and value of IV 67108864
loop count value is 27 and value of IV 134217728
loop count value is 28 and value of IV 268435456
loop count value is 29 and value of IV 536870912
loop count value is 30 and value of IV 1073741824
loop count values is 1 and value of IV 2
loop count values is 2 and value of IV 4
loop count values is 3 and value of IV 8
loop count values is 4 and value of IV 16
loop count values is 5 and value of IV 32
loop count values is 6 and value of IV 64
loop count values is 7 and value of IV 128
loop count values is 8 and value of IV 256
loop count values is 9 and value of IV 512
loop count values is 10 and value of IV 1024
loop count values is 11 and value of IV 2048
loop count values is 12 and value of IV 4096
loop count values is 13 and value of IV 8192
loop count values is 14 and value of IV 16384
loop count values is 15 and value of IV 32768
loop count values is 16 and value of IV 65536
loop count values is 17 and value of IV 131072
loop count values is 18 and value of IV 262144
loop count values is 19 and value of IV 524288
loop count values is 20 and value of IV 1048576
loop count values is 21 and value of IV 2097152
loop count values is 22 and value of IV 4194304
loop count values is 23 and value of IV 8388608
loop count values is 24 and value of IV 16777216
loop count values is 25 and value of IV 33554432
loop count values is 26 and value of IV 67108864
loop count values is 27 and value of IV 134217728
loop count values is 28 and value of IV 268435456
loop count values is 29 and value of IV 536870912
loop count values is 30 and value of IV 1073741824

Add a comment
Know the answer?
Add Answer to:
JAVA HELP! Question: Write a Java console application that investigates how well Java handles large integers....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a Java console application that Create a text file called Data.txt. Within the file, use...

    write a Java console application that Create a text file called Data.txt. Within the file, use the first row for the name and data title, and use the second row for column headers. Within the columns, insure that the first column is a label column and other columns contain numeric data. In your application, read file Data.txt into parallel arrays, one for each column in the file. Create method printArrays to print the header row(s) and the (unsorted) data in...

  • This assignment tests your ability to write C programs that handle keyboard input, formatted console output,...

    This assignment tests your ability to write C programs that handle keyboard input, formatted console output, and input/output with text files. The program also requires that you use ctype functions to deal with the logic. In this program, you will input from the user two characters, which should both be letters where the second letter > the first letter. You will then input a file character-by-character and output those letters that fall between the two characters (inclusively) to an output...

  • *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods...

    *Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...

  • I only need help with the constructors and add method. Thanks! Background Arbitrary length integers are...

    I only need help with the constructors and add method. Thanks! Background Arbitrary length integers are integers that have no size restriction. Recall that the int type has a range of -2,147,483,648 to 2,147,483,647. The long type runs from -263 to 263 - 1. Sometimes these numbers are not large enough. One example application that may need larger numbers is public-key cryptography where very large integers are used to make decryption hard. A large integer may be represented as a...

  • Please help me code the following in: JAVA Please create the code in as basic way...

    Please help me code the following in: JAVA Please create the code in as basic way as possible, so I can understand it better :) Full points will be awarded, thanks in advance! Program Description Write a program that demonstrates the skills we've learned throughout this quarter. This type of project offers only a few guidelines, allowing you to invest as much time and polish as you want, as long as you meet the program requirements described below. You can...

  • How can help me to create this program? PartADriver public class PartADriver {    public static...

    How can help me to create this program? PartADriver public class PartADriver {    public static void main (String [] args)    { // create two martians Martian m1 = new Martian(); Martian m2 = new Martian("Grey", 3); // display both martians Output.showMessage("After instantiation.\n" + "Martian #1: " + m1.toString() + "\nMartian #2: " + m2.toString()); // make the first martian speak 3 times for (int count = 0; count < 3; count++)    m1.speak(); // make the second martian...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • You will write a two-class Java program that implements the Game of 21. This is a...

    You will write a two-class Java program that implements the Game of 21. This is a fairly simple game where a player plays against a “dealer”. The player will receive two and optionally three numbers. Each number is randomly generated in the range 1 to 11 inclusive (in notation: [1,11]). The player’s score is the sum of these numbers. The dealer will receive two random numbers, also in [1,11]. The player wins if its score is greater than the dealer’s...

  • Needs Help with Java programming language For this assignment, you need to write a simulation program...

    Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...

  • Hello, I am having trouble with this C++ programming assignment. If someone could write the code...

    Hello, I am having trouble with this C++ programming assignment. If someone could write the code or at least part of it that would help me, because every code I try has errors. Using if Statements, Loops and Nested Loops • Scanning Characters in a String Using a Loop • Performing Character Arithmetic In project, you will write an interactive program that, counts the number of digits in a non-negative integer, factorizes the integer into powers of ten and its...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT