Question

In: Computer Science

Correct the code to prints the following: 0 1 2 3 4 5 6 7 8...

Correct the code to prints the following:

0 1 2 3 4 5 6 7 8 9

int[] numbers = new int[10];

for(int i=0; i < numbers.length; ++i)

        numbers[i] = i * 3;

for(int i=0; i < numbers.length; ++i)

        System.out.print(numbers[i] / 2 + 1 + " ");

System.out.println();

Solutions

Expert Solution

Below is the correct code which prints the following:

0 1 2 3 4 5 6 7 8 9

Code:-

import java.io.*;

public class test {
   public static void main(String [] args)
   {
       int[] numbers = new int[10];
       for(int i=0; i<numbers.length; ++i)
           numbers[i] = i*2;
       for(int i=0; i<numbers.length; ++i)
           System.out.print(numbers[i]/2 + " ");
       System.out.println();
   }
}

Output:-

If you have any doubts please comment will try to solve as soon as possible. Thank you :)


Related Solutions

A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8...
A = (1 −7 5 0 0 10 8 2 2 4 10 3 −4 8 −9 6) (1) Count the number of rows that contain negative components. (2) Obtain the inverse of A and count the number of columns that contain even number of positive components. (3) Assign column names (a,b,c,d) to the columns of A. (4) Transform the matrix A into a vector object a by stacking rows. (5) Replace the diagonal components of A with (0,0,2,3). Hint:...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5...
DATA 3 8 2 15 2 2 0 0 4 5 2 7 0 1 5 3 0 2 5 4 1 6 9 5 3 1 2 10 6 1 1 2 1 19 6 6 6 7 0 4 1 1 1 0 1 9 2 2 2 1 16 10 10 5 2 3 1 4 4 4 3 6 2 8 5 2 7 1 6 4 0 3 1 1 1 Background: A group of...
Matrix A2= [1 2 3; 4 5 6; 7 8 9; 3 2 4; 6 5...
Matrix A2= [1 2 3; 4 5 6; 7 8 9; 3 2 4; 6 5 4; 9 8 7] Note: TA2 is defined to be a linear transformation that maps any vector x to A2* x. That is TA2 = A2*x. Also the range of the Linear transformation represented by A2 is the same as the column space of A2. l) Find a basis for the null(TA2). m) Find nullity of A2, TA2 and A2tA2. n) Find rank(A2), rank(A2t),...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6 13 7 33 8 42 9 66 10 77 11 105 12 103 13 110 14 105 15 84 16 70 17 51 18 40 19 27 20 27 21 15 22 5 23 7 24 2 25 2 26 1 27 0 28 0 29 0 30 0 (7) On the Histogram worksheet, calculate all frequencies of the distribution using the table shown....
Find regression line for the data X 0   1   2   3    4   5   6   7  8          &nbsp
Find regression line for the data X 0   1   2   3    4   5   6   7  8               [3 MARKS] Y 11 21 31 41 51 61 71 81 91 b. X  0   2   4   6   8  10                            [3 MARKS]       Y  12 15 17 18 20 22
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C,...
Hexadecimal digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. How many hexadecimal strings of length twelve have five A’s and five B’s? How many hexadecimal strings of length twelve have at most three E’s? How many hexadecimal strings of length twelve have exactly three A’s and at least two B’s? How many hexadecimal strings of length twelve have exactly two A’s and exactly two B’s, so that the two...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7...
x 2 8 5 9 4 3 9 6 7 8 y 3 6 5 7 9 7 4 6 9 9 -5.48x + 0.17 5.48x + 0.17 -0.17x + 5.48 0.17x + 5.48
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1...
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1 0 2 11 5 11 27 4 0 6 Create Standard Deviation Chart (Normal Distribution Curve)
Given the unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] P E R...
Given the unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] P E R Y I H J L S Suppose this array were being sorted using the quick sort algorithm from the course content, into ASCENDING order, with the left-most item as the pivot value. List the letters in the resulting array, in order AFTER the FIRST PARTITIONING. [0] [1] [2] [3] [4] [5] [6] [7] [8]
Preform the following calculations on the sample below: { 6, 2, 0, 4, 7, 8, 5,...
Preform the following calculations on the sample below: { 6, 2, 0, 4, 7, 8, 5, -1, 7, -2, 0 } What is the sample size of the dataset Calculate the mean Find the median Find the mode Calculate the sample variance and sample standard deviation ) Find the 10th and 75th percentile of the data ().
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT