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
Your southern region is not doing very well. You want to know why, so you ask for a special report showing the numbers for the s
Mila [183]

Answer:

D) Comparative

Explanation:

Comparative report is an analytical approach to report writing, where the aim is to determine the performance or contribution of individual constituents.

6 0
2 years ago
Check your tire pressure every _____. A. month B. two months C. six months D. year
ohaa [14]

Answer: I'd say (B) Two months

Explanation: Hope its correct and helps, Good luck :)

6 0
2 years ago
Read 2 more answers
In a particular field, there are trees in a l single row from left to right. Each tree has a value V You cut trees from left to
Sedbober [7]

Answer:

i dont know help me

Explanation:

4 0
1 year ago
Read 2 more answers
A mobile device user has tried to install a new app numerous times without success. She has closed all unused apps, disabled liv
elena-14-01-66 [18.8K]

The correct answer is B. Check for sufficient available storage space.  

Explanation:

One of the factors that can cause it is not possible to install a new app is insufficient storage as space in the mobile device is needed to save the app. This can be easily solved either by deleting apps and other content or expanding the memory available through a Micro SD card. Also, before attempting any major procedure such as a complete reset it is important to check the storage space availability. In this context, the user should check for sufficient available storage space (option B) because this might be the cause of the issue she is experiencing; also, this is a basic step before considering others such as performing a factory reset.

6 0
2 years ago
The president of the company wants a list of all orders ever taken. He wants to see the customer name, the last name of the empl
blsea [12.9K]

Answer:

see explaination

Explanation:

Check the SQL query below:

SELECT c.CustomerName, e.LastName, s.ShipperName, p.ProductName, o.Quantity, od.OrderDate

FROM

Customers c, Employee e, Shippers s, Orders o, OrderDetails od, Product p

WHERE c.customerID = o.customerID AND

e.employeeID = o.employeeID AND

o.orderID = od.orderID AND

od.shipperID = s.shipperID AND

od.productID = p.productID;

6 0
2 years ago
Other questions:
  • What is a typical grace period for a credit card...
    15·2 answers
  • Assume that name has been declared suitably for storing names (like "Misha", "Emily" and "Sofia"). Assume also that stdin is a v
    9·1 answer
  • After experiencing several issues with an Active Directory domain controller, you have decided to perform a restore operation on
    10·1 answer
  • Brandon purchased a new processor online as an upgrade. When he purchased the processor, he made sure that it used the same sock
    14·1 answer
  • ANSI defines four events that signal the end of a transaction. Of the following events, which is defined by ANSI as being equiva
    14·1 answer
  • Use the values in the range A7:A8 to extend the list of years to the range A9:A11. 3. Use AutoFill to fill the range A9:H11 with
    5·1 answer
  • Modify the closest pair of points algorithm so that the separating line L now separates the first n/4 points (sorted according t
    14·1 answer
  • Look at the following array definition:
    11·1 answer
  • 1.1.5 practice: analyzing business culture
    13·1 answer
  • daniel wants to buy a computer to use for playing games after work. he loves racing games and wants to make sure his device has
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!