In Java please.
This problem can be done in main. Apply the increment operator (++) 10 million times, first to an Integer reference and then to a variable of type int, each set initially to 1. Compare the running times.
To compare running times we use the method long System.currentTimeMillis()
that returns the current time in milliseconds.
For both the Integer reference x and the primitive y, the main method
Code:
public class Main
{
public static void main(String[] args) {
int y=1;
Integer x=1;
long
startingtimeofi,endingtimeofi,startingtimeofI,endingtimeofI,elapsedtimeofi,elapsedtimeofI;
startingtimeofi=System.currentTimeMillis(); //records
the starting time in milliseconds,
while(y<=10000000)
{
y++; //increments a variable 10,000,000 times
}
endingtimeofi=System.currentTimeMillis();
elapsedtimeofi=endingtimeofi-startingtimeofi;
//calulating the elapsed time= ending time - starting time
System.out.println("Running time for int y is
"+elapsedtimeofi);//displays the elapsed time of int y
startingtimeofI=System.currentTimeMillis();
////records the starting time in milliseconds,
while(x<=10000000)
{
x++; //increments a variable 10,000,000 times
}
endingtimeofI=System.currentTimeMillis();
elapsedtimeofI=endingtimeofI-startingtimeofI;
////calulating the elapsed time= ending time - starting time
System.out.println("Running time for Integer x is
"+elapsedtimeofI);//displays the elapsed time Integer x
}
}

Output:

Note:
Please comment if you face any difficulty
In Java please. This problem can be done in main. Apply the increment operator (++) 10...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
in
java
Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....
java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code I'll tell you what to do. Use other code as a guide. Start with a for loop with a start of int i = 0 Set the ending point of when i is less than the length of the arr array. Set the incrementation to increase i by 1 using the unary operator ++. Within the loop set the arr...
java Operating System Scheduler Two scheduling strategies for an operating system scheduler are first come first serve (FCFS) and fixed priority pre-emptive scheduling (FPPS). Since queues operate on a first come first serve basis, FCFS is implemented using a queue. Similarly, FPPS is implemented using a priority queue. The operating system scheduler simulation is already provided for you. To use it you simply need to modify the main method to run the simulator using either the LinkedListQueue or the PriorityQueue. Run...
Need some help on homework practice problems, Thank you in advance! Problem 1: Write a method, parallelSum(), that uses the fork-join framework to compute the sum of the elements of an array. Its skeleton as well as its Javadoc is provided in the file ParallelSum.java. Simple code for testing and timing your method is also provided in the main method. This problem is essentially the same as ParallelMax in structure. Therefore, follow the code for ParallelMax to complete ParallelSum. Problem...
Write a java program: Create a method fillRandom() that accepts an array of int as input and populates it with random numbers in the range -999 to 1000 Explicitly store zero in index [0] and 900 in index [1]. (0 and 900 will be used as search keys) Create a method DisplayLastInts() that accepts an array of int as input and displays the last hundred elements to the screen in rows of 10 elements. Format the output so the 10...
-------------------------------------------------------------------- 1. How does Java support the concept of encapsulation? -------------------------------------------------------------------- 2. Describe the difference between an object and a class. -------------------------------------------------------------------- 3. What is the difference between the contents of a Java variable of a primitive type and a Java variable of a class type? -------------------------------------------------------------------- 4. (a) How is a 'static' class method different from a regular (non-static) class method? (b) How is a 'static' variable in a class different from a regular (instance) variable in a class?...
Can someone please help me with the following java assignment. So in this assignment you will begin with the starterProject I provide and then add to it. I am also asking that before you begin you really look at the starterProject because this is the object-oriented basics. The starterProject is the exact same as the ClassClockExample.zip in Module 5. I’ve also done this using a clock because it is something that you already know how it works. Remember that OOD and OOP is...
Please use JAVA program language Discrete event simulation is to simulate events occurring at discrete time points. Between any two consecutive time points, no event occurs. (a) Write a class Event with two integer instance variable time and type, which represents an event of a specific type occurs at time. Also write the constructor Event(int time, int type), which initializes the attributes using the parameters. In using this class, you can assume the getter and setter methods are available. (b)...
please answer question use JAVA!!
PROBLEM 1: Phoney Data Initially, we will use the data input to create a report of all location data gathered from the phone customers. Processing 1) Read in the location data and the customer data. Use arrays (consider multidimensional arrays) to store this information. 2) You have been given a method call formatTime that takes in an integer 24-hour time (hhmM) and returns that time as a string in the form "HH:MM". All method details...