Question

System out printin largest 2 Generate a set 100 ra

do number two in java

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

import java.util.*;

public class LongestSequence
{
public static void main(String a[])
{
int n=0,p=-100, l_seq=0, seq=0, index=-1;
int[] num= new int[100];
  
Random r=new Random();

for(int i=0;i<100;i++)
{
n=r.nextInt((100 - 1) + 1) + 1;
num[i]=n;
System.out.print(n+" ");
if((n-1)==p)
{
l_seq++;
p=n;
if(l_seq > seq)
{
seq=l_seq;
index=i;
}
}
else
{
p=n;
l_seq=1;
}

}
  
System.out.print("\nThe longest sequence is: ");
for(int i=index-seq+1;i<=index;i++)
System.out.print(num[i]+" ");
}
}

Add a comment
Know the answer?
Add Answer to:
do number two in java System out printin largest 2 Generate a set 100 random integer...
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
  • Please do both parts (in Java); thanks! An Armstrong number of three digits is an integer...

    Please do both parts (in Java); thanks! An Armstrong number of three digits is an integer such that the sum of the cubes of its digits is equal to the number itself. For example, 371 is an Armstrong number since 3^3 + 7^3 + 1^3 = 371. Draw the flowchart and write a Java code to find ALL Armstrong number in the range of 0 and 999. You should write your code in two ways: (Yes as if you are...

  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • Part 2 -Arrays We can use the Math.random method to generate random integers. For example, Math.r...

    Please write a JAVA program according to following requirement. Thanks Part 2 -Arrays We can use the Math.random method to generate random integers. For example, Math.random () generates a random integer greater than or equal to 0 and less than 1. The expression Math. random) 6generates random numbers between 0 and 5, simulating the throw of a die. In this lab assignment, you will use an array to test whether the random generator is fair; that is, whether each possible...

  • repl,it HW 11.2 Please verify your em back to classroom run i.mport random 2 # DO...

    repl,it HW 11.2 Please verify your em back to classroom run i.mport random 2 # DO NOT DELETE you may want to collapse it. 4- def generate_number_strings (): 3 wGenerates a string that contai ns digits and spaces. 6 numbers- 7 rng range(random.randint (1, 20) 8 for i in rng: 10- if (len(numbers)> and numbers[-1:] != and i !-rng. stop and random.randint (0, 10) % 50): 11 12 13 1 14- numbers + 15 else: 16- numbers +str(random . randint...

  • Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that...

    Java CSC252   Programming II    Static Methods, Enums, Constants, Random Rock Paper Scissors Write a program that allows the user to play "Rock, Paper, Scissors". Write the RPS class. All code should be in one file. main() will be part of the RPS class, fairly small, and contain only a loop that asks the user if they want to play "Rock, Paper, Scissors". If they say yes, it calls the static method play() of the RPS class. If not, the program...

  • !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random...

    !!!!!!!Java!!!!! When you are confident that your methods work properly and that you can generate random text with my generateText method, you can move on to the second step. Create a third class called Generator within the cs1410 package. Make class. This class should have a main method that provides a user interface for random text generation. Your interface should work as follows: Main should bring up an input dialog with which the user can enter the desired analysis level...

  • Write a Java program, In this project, you are going to build a max-heap using array...

    Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...

  • Make a program using Java that asks the user to input an integer "size". That integer...

    Make a program using Java that asks the user to input an integer "size". That integer makes and prints out an evenly spaced, size by size 2D array (ex: 7 should make an index of 0-6 for col and rows). The array must be filled with random positive integers less than 100. Then, using recursion, find a "peak" and print out its number and location. (A peak is basically a number that is bigger than all of its "neighbors" (above,...

  • I need help making this work correctly. I'm trying to do an array but it is...

    I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...

  • Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If...

    Java Project Name: IC19_WinningTheLottery n this assignment, we're going to attempt to win the lottery! (**If you do actually win the lottery, please be sure to give back to your alma mater, Orange Coast College. We will be happy to put your name on the building!**) Ok, time to get real. The Fantasy 5 (TM) lottery is a game in which 5 numbers from 1 to 36 are randomly drawn by the State of California. If you correctly guess all...

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
Active Questions
ADVERTISEMENT