Question

C# Code please with picture of code.Thanks! 1. Create a Main method, and create a 2D...

C# Code please with picture of code.Thanks!

1. Create a Main method, and create a 2D integer array called data, with a size of five (5) by five (5). Ask the user to input the values for this array (Scanner’s nextInt)

  1. 2.Create a method called LongestPositiveSeries, that takes in a 2D array and finds the length of the longest continuous series of positive numbers in it.
    For example, if we had an array like this:

0

1

2

3

4

5

-1

-5

-5

5

3

-2

56

25

-15

0

5

5

0

324

46

25

0

0

0

    • The length would be 5. For this problem, 0 is considered non-negative and not positive, so we start counting from index [0, 1] (which is 1) to [1, 0] (which is 5) and end at index [1, 1] (which is –1).
    • Hint: Consider using a basic linear search and modifying it to keep track of the current positive streak of numbers.
  1. 3. Call that method in your Main, for the array data.
  2. 4. Print out the returned result from your method in your Main, along with the content of data.
  3. C# CODE

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

Code -

using System;
public class MultiArrayExample
{
public static void Main(string[] args)
{
//2d array initialized
int[,] arr = { { 0, 1, 2, 3, 4 }, { 5, -1, -5, -5, 5 }, { 3, -2, 56, 25, -15 }, { 0, 5, 5, 0, 324}, { 46, 25, 0, 0, 0 } };//declaration and initialization
//print the output return by LongestPositiveSeries function
Console.Write("Longest Positive Series: "+LongestPositiveSeries(arr));
}
//function to return LongestPositiveSeries
public static int LongestPositiveSeries(int[,] arr){
//variable declare
int maxCount = 0,maxCountNow =0;
//iterate through array
for(int i=0;i<5;i++){
for(int j=0;j<5;j++){
//compare arr[] is less than 0
if(arr[i,j]<=0){
if(maxCount<maxCountNow){
maxCount = maxCountNow;
}
maxCountNow = 0;
}
//if arr[] is greater than 0
if(arr[i,j]>0){
maxCountNow++;
}
}   
}
return maxCount;
}
}

Screenshots -

pls do give a like thank you

Add a comment
Know the answer?
Add Answer to:
C# Code please with picture of code.Thanks! 1. Create a Main method, and create a 2D...
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
  • Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method...

    Programming 5_1: Create a Java class named <YourName>5_1 In this class create a main method, but for now leave it empty. Then write a Java method getAverage which takes an array of integers as it’s argument. The method calculate the average of all the elements in the array, and returns that average. The method should work for an array of integers of any length greater than or equal to one. The method signature is shown below: public static double getAverage(...

  • Part 1- Method practice Create a main method. In there, make an array of 100 random...

    Part 1- Method practice Create a main method. In there, make an array of 100 random integers(numbers between 0 and 1000). Create a method to find average of the array. Pass the array and return the number(double) that is the average In the main method, call the method created in Step 2. Print out the average Create a method to find the min value of the array. Pass the array and return the int that is the smallest.(pass the value...

  • The last element in each array in a 2D array is incorrect. It’s your job to...

    The last element in each array in a 2D array is incorrect. It’s your job to fix each array so that the value 0 is changed to include the correct value. In the first array, the final value should be the length of the first array. In the second array, the final value should be the sum of the first value, and the second to last value in the array. In the third array, the final value should be the...

  • Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method...

    Step 1. Start Netbeans and create a project called ArrayLab Step 2. Write the main method  Declare and initialize an array called myNums int myNums = {3, 8, 12, 4, 2, 9, 6};  Declare an int called largestNum and set it to 0.  Write a for loop that prints the array for (int index = 0; index < myNums.length; index++) { System.out.println(myNums[index] + “ “); }  Write a for loop that prints the array backwards ...

  • Java programming: I need to create a method that is given a 2D char array and...

    Java programming: I need to create a method that is given a 2D char array and a String that returns a part of the original 2D array. The input string will tell the method which rows from the input array need to be returned. For example, a 5x5 char array input along with a string "0 4" would return rows 1 and 5 of the input array. The String input will always be numbers divided by spaces and will not...

  • Please code in C thank you. 1. Create an array with 20 random numbers between 1...

    Please code in C thank you. 1. Create an array with 20 random numbers between 1 and 100. Incorporate the following specifications. • Send the base address of the array and an integer to a function called sort(). • The integer is a user input which is either 0 or 1. If the user does not enter either 0 or 1, keeping asking the user until you get the right input. • If the user input is 0, sort the...

  • Please send this C++ code with ( // ) Comments 1. In main, you have the...

    Please send this C++ code with ( // ) Comments 1. In main, you have the following array declared: int arr[5] = {1, 5, 3, 2} a. What are the elements in the array? Create a function called displayArr that accepts the array and the size of the array, and displays every element in the array. b. Create a function called findAverage that accepts the array and the size of the array as arguments, and returns the average of all...

  • You will create a program with two methods, the main() method of course and another method...

    You will create a program with two methods, the main() method of course and another method called printArray(). The main method will define an array of 5 elements. A loop will be used to prompt the user to enter 5 numeric values which will go into the 5 array elements. The main() method will then call the printArray() method passing the array by reference, and the array length by value. The printArray() method will then print the contents of the...

  • Write a java program: Create a method fillRandom() that accepts an array of int as input...

    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...

  • java code please 14. Next we'll complete the setValues() method. Instead of giving you exact code...

    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...

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