answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olchik [2.2K]
2 years ago
6

Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the elemen

t. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}.
Computers and Technology
2 answers:
Veseljchak [2.6K]2 years ago
6 0

Answer:

import java.util.Scanner;

public class StudentScores {

public static void main(String[] args) {

 int len = 5;

 int i;

 int[] lowerScores = new int[len];

 lowerScores[0] = 5;

 lowerScores[1] = 0;

 lowerScores[2] = 2;

 lowerScores[3] = -3;

 System.out.println("The original elements of array are ");

 for (i = 0; i < len; i++)

 {

  System.out.print(lowerScores[i] + " ");

 }

  System.out.println();

 System.out.println("The modified elements of array are ");

 for (i = 0; i < len; ++i)

 {

  if (lowerScores[i] < 0) {

   lowerScores[i] = 0;

  } else if (lowerScores[i] > 0) {

   lowerScores[i] = lowerScores[i] - 1;

  }

 }

 for (i = 0; i < lowerScores.length; ++i) {

  System.out.print(lowerScores[i] + " ");

 }

 System.out.println();

}

}

Explanation:

The code is missing for loop:  for (i = 0; i < lowerScores.length; ++i)

for (i = 0; i < lowerScores.length; ++i) {

  System.out.print(lowerScores[i] + " ");

 }

Xelga [282]2 years ago
5 0

Answer:

The JAVA program to implement for loop for given scenario is shown below.

public class MyProgram {

   public static void main(String args[]) {    

     int len = 5;

     int[] lowerScores = new int[len];      

     lowerScores[0] = 5;

     lowerScores[1] = 0;

     lowerScores[2] = 2;

     lowerScores[3] = -3;      

     System.out.println("The original elements of array are ");

     for(int i=0; i<len; i++)

     {

         System.out.print(lowerScores[i]+" ");

     }      

     System.out.println();

     System.out.println("The modified elements of array are ");

     for(int i=0; i<len; i++)

     {

         // if element is 0 or negative, 0 is assigned to this index

         if(lowerScores[i] <= 0)

           lowerScores[i] = 0;

       // 1 is subtracted from every non zero and positive element

         else

           lowerScores[i] = lowerScores[i] - 1;

           

       System.out.print(lowerScores[i]+" ");

     }

   }

}

OUTPUT

The original elements of array are  

5 0 2 -3 0  

The modified elements of array are  

4 0 1 0 0

Explanation:

The integer array is declared as shown.

int[] lowerScores = new int[len];

The length of the array is given by integer variable len. As per the question, we have taken four elements and size of 5 for the given array.

int len = 5;

The elements of the array are initialized inside the program with the elements given in the question.

lowerScores[0] = 5;

      lowerScores[1] = 0;

The values of the array can be changed to test the program. Also, the size of the array can be changed for testing.

As per the given scenario, if the element is greater than zero, 1 is subtracted from this element. For elements less than or equal to zero, that particular element is assigned the value of 0.

The given program implements if else statement inside for loop for this purpose.

for(int i=0; i<len; i++)

     {

         // if element is 0 or negative, 0 is assigned to this index

         if(lowerScores[i] <= 0)

           lowerScores[i] = 0;

       // 1 is subtracted from every non zero and positive element

         else

           lowerScores[i] = lowerScores[i] - 1;

     }  

You might be interested in
Spark is electrical discharge in air, while air is mix of variety of gases what particles conduct electricity in gas
erastova [34]

Answer:

Mercury, rontgen rays, etc.

Explanation:

There are lots of answers to this question, hope these two help.

6 0
1 year ago
To keep from overwriting existing fields with your Lookup you can use the ____________ clause.
Radda [10]
I believe the answer is <span>outputnew
</span>The main difference between the output new and the output is that outputnew won't overrite the alredy existing description field.
If you don't put this clause, <span>Splunk would adds all the field names and values to your events by through the lookup.</span>
3 0
2 years ago
Read 2 more answers
The Vice President (VP) of Customer Support for Universal Containers has issued a mission statement that "We will empower our cu
elena-14-01-66 [18.8K]

Answer: The three most appropriate options are:

options C, D E

Explanation:

(1) Enabling customers to be emailed FAQs by accessing the interactive voice response 24 hours a day helps consultant achieve mission statement.

(2) Also, mobile devices should have the same support as desktops for mobile devices customer community and should be well optimized.

(3) Consultant will achieve mission statement if a central "Contact Us" page is created which provides access to all available channels.

3 0
2 years ago
A workgroup database is a(n) _____ database
Step2247 [10]
It is a shared database
8 0
2 years ago
a.Write a Python function sum_1k(M) that returns the sum푠푠= ∑1푘푘푀푀푘푘=1b.Compute s for M = 3 by hand and write
stealth61 [152]

Answer:

def sum_1k(M):

   s = 0

   for k in range(1, M+1):

       s = s + 1.0/k

   return s

def test_sum_1k():

   expected_value = 1.0+1.0/2+1.0/3

   computed_value = sum_1k(3)

   if expected_value == computed_value:

       print("Test is successful")

   else:

       print("Test is NOT successful")

test_sum_1k()

Explanation:

It seems the hidden part is a summation (sigma) notation that goes from 1 to M with 1/k.

- Inside the <em>sum_1k(M)</em>, iterate from 1 to M and calculate-return the sum of the expression.

- Inside the <em>test_sum_1k(),</em> calculate the <em>expected_value,</em> refers to the value that is calculated by hand and <em>computed_value,</em> refers to the value that is the result of the <em>sum_1k(3). </em>Then, compare the values and print the appropriate message

- Call the <em>test_sum_1k()</em> to see the result

8 0
1 year ago
Other questions:
  • Susan needs to change the color scheme in all the slides of her multimedia presentation. The presentation software program Susan
    10·2 answers
  • The icacls.exe command adds __________, which are visible by clicking the Advanced button in the folder Properties dialog box
    15·1 answer
  • Write a statement to add the key Tesla with value USA to car_makers. Modify the car maker of Fiat to Italy. Sample output for th
    9·1 answer
  • 8.Change the following IP addresses from binary notation to dotted-decimal notation: a.01111111 11110000 01100111 01111101 b.101
    10·1 answer
  • Leah wants to create a PowerPoint presentation for a history report about the progressive era in the 1900s. To
    6·2 answers
  • Our new catalog contains an eclectic collection of items
    6·1 answer
  • Consider the following 3-PARTITION problem. Given integers a1; : : : ; an, we want to determine whether it is possible to partit
    10·1 answer
  • 1. Assign to maxSum the max of (numA, numB) PLUS the max of (numY, numZ). Use just one statement. Hint: Call FindMax() twice in
    7·1 answer
  • Java Programming home &gt; 1.14: zylab training: Interleaved input/output Н zyBooks catalog Try submitting it for grading (click
    6·1 answer
  • Accenture has partnered with a global construction company that specializes in building skyscrapers. The company wants better ma
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!