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...
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)
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 ().
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1...
Given: x y -5 1 -4 5 -3 4 -2 7 -1 10 0 8 1 9 2 13 3 14 4 13 5 18 What are the confidence limits (alpha = 0.05) for the true mean value of Y when X = 3?
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT