1answer.
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
Assoli18 [71]
3 years ago
12

Write a short program that uses a for loop to populate an array. The array can store up to 10 integers. Modify the code slightly

to create a bug that would prevent the code from compiling or even better from running correctly. Be sure to describe what the code is designed to do. Monitor the post to comment when other students work to repair your code.
Computers and Technology
1 answer:
mr Goodwill [35]3 years ago
8 0

Answer:

  1. public class num16 {
  2.    public static void main(String[] args) {
  3.        //This code is designed to create and populate an array with
  4.        //Ten Integer values
  5.        Scanner in = new Scanner(System.in);
  6.        //Create the array
  7.        int [] intArray = new int [10];
  8.        //populating the array
  9.        for(int i =0; i<=10; i++){
  10.            System.out.print("Enter the elements: ");
  11.            intArray[i]= in.nextInt();
  12.        }
  13.        //Print the Values in the array
  14.        System.out.println(Arrays.toString(intArray));
  15.    }
  16. }

Explanation:

  • The above code looks like it will run successfully and give desired output.
  • But a bug has been introduced on line 9. This will lead to an exception called ArrayIndexOutOfBoundsException.
  • The reason for this is since the array is of length 10, creating a for loop from 0-10 will amount to 11 values, and the attempt to access index 10 for the eleventh element will be illegal
  • One way to fix this bug is to change the for statement to start at 1.
You might be interested in
Write a qbasic program to design any simple software with output ​
andreev551 [17]

Answer:

CLS

PRINT "Hello World"

Explanation:

A generic question with a generic answer.

7 0
3 years ago
Write a program that asks the user for three strings. Then, print out whether the first string concatenated to the second string
ipn [44]

Answer:

import java.util.Scanner;

public class num5 {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Enter The First String");

       String str1 = in.next();

       System.out.println("Enter The Second String");

       String str2 = in.next();

       System.out.println("Enter The Third String");

       String str3 = in.next();

       String oneAndTwo = str1+str2;

       if(str3.equals(oneAndTwo)){

           System.out.println(str1+" + "+str2+" is equal to "+str3+"!");

       }

       else

           System.out.println(str1+" + "+str2+" is not equal to "+str3+"!");

   }

}

Explanation:

  • Implemented in Using Java Programming Language
  • Import Scanner Class to prompt and receive users' input
  • Create three string variables and store the three values entered by the user (str1, str2 and str3)
  • Concatenate str1 and str2 using the + operator and assign to a new variable
  • Use the if statement with Java's .equals() method to check for equality of the new string with the third string
  • Print the appropriate message if the equal or not
8 0
3 years ago
HELP PLEASE!!!!
denis23 [38]

Answer:

1100 ; 11000 ; 110000 ; 1100000

Explanation:

Converting the following decimals to binary :

2__12

2__6 r 0

2__3 r 0

2__1 r 1

___0 r 1

12 = 1100 base 2

2.)

2__24

2__12 r 0

2__6 r 0

2__3 r 0

2__1 r 1

___0 r 1

24 = 11000 base 2

2__48

2__24 r 0

2__12 r 0

2__6 r 0

2__3 r 0

2__1 r 1

___0 r 1

48 = 110000 base 2

2__96

2__48 r 0

2__24 r 0

2__12 r 0

2__6 r 0

2__3 r 0

2__1 r 1

___0 r 1

96 = 1100000 base 2

5 0
3 years ago
A nonlinear optimization problem is any optimization problem in which at least one term in the objective function or a constrain
MAXImum [283]

Answer:

Yes

Explanation:

A nonlinear optimization problem is indeed a optimization problem in which there are nonlinear elements involved either as the objective function or one or more constraints may be nonlinear also. Let me show you an example. Let optimize de following function:

f(x) = x_{1} +x_{2}

These are the constraints:

x_{1} \geq  0\\x_{2} \geq  0\\\\x_{1} ^{2} +  x^{2}_{2}  \geq  1

The last constraint consists on nonlinear elements, so this problem in fact a nonlinear optimization problem.

5 0
3 years ago
Dov'è il mio formaggio
fredd [130]

Answer:

non lo so, mi spiace

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • What feature did the 32X add to the Sega Genesis?
    13·1 answer
  • QUESTION 7 of 10: A surplus can be best defined as:
    10·1 answer
  • Identify ways you can manage a project using project management software
    14·1 answer
  • What is a CPU or a GPU? What’s the difference? Which one is better?
    5·1 answer
  • Why do hard drives tend to slow down over time?
    11·2 answers
  • Imagine that you have configured the enable secret command, followed by the enable password command, from the console. You log o
    9·1 answer
  • printArray is a method that accepts one argument, an arrayof int. The method prints the contents of the array; it does not retur
    5·1 answer
  • What are 2 ways to access the vendor credit screen in quickbooks online?
    13·1 answer
  • You are dropping your friend back home after a night at the movies. From the car, she turns on the indoor lights in her home usi
    9·1 answer
  • Write a function named parts that will take in as parameters the dimensions of the box (length, width, and height) and the radiu
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!