Ask Experts Questions for FREE Help !
Ask
    iamjmael's Avatar
    iamjmael Posts: 4, Reputation: 1
    New Member
     
    #1

    Feb 16, 2016, 10:58 PM
    Array need help
    Write a program that will ask the user to enter a number and then place the 10 consecutive numbers in a single-dimensional array starting from the number entered by the user. The program will then display the elements inside index 2 and 4 and 6.
    kcomissiong's Avatar
    kcomissiong Posts: 1,166, Reputation: 276
    Ultra Member
     
    #2

    Feb 17, 2016, 02:51 AM
    If you need help, please post the particular area you are struggling with and what you have tried. If you want someone to do this for you, pay a programmer.
    iamjmael's Avatar
    iamjmael Posts: 4, Reputation: 1
    New Member
     
    #3

    Feb 17, 2016, 03:03 AM
    import java.util.*;
    public class SetB4
    {
    public static void main(String args[])
    {
    int[] a=new int[10];
    Scanner sc=new Scanner(System.in);
    System.out.println("Please enter elements...");
    for(int j=0;j<10;j++)
    a[j]=sc.nextInt();


    }
    }






    ------------------------------
    sorry kcomissiong :)
    this program work but the problem
    is I'm struggle to print the output...
    I try the
    System.out.println([2][4][5]);
    but it didn't work it say illegal statement :(
    need help
    CravenMorhead's Avatar
    CravenMorhead Posts: 4,532, Reputation: 1065
    Adult Sexuality Expert
     
    #4

    Feb 17, 2016, 08:46 AM
    first off you are asking the user to put in 10 numbers, not put in 1 number and then populate the array. This might be nit picking though.

    It should be:

    system.out.println("Enter the number");
    int baseNumber = sc.nextInt();
    for(I=0;i<10;i++)a[i]=i+1+baseNumber;

    Printing it out you need to index the proper elements:

    printf(" Elements, 2,4,6 are: %d %d %d", a[2], a[4], a[6]);

    Figure out how to output variables and make sure you're indexing the proper place in the array. Google how if you're confused. That is how I, being a brilliant programmer, figure things like this out.
    iamjmael's Avatar
    iamjmael Posts: 4, Reputation: 1
    New Member
     
    #5

    Feb 18, 2016, 01:57 AM
    Thank you CravenMorhead :)

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Array help and file io [ 2 Answers ]

I need help multiplying 2d arrays from and input file (input.txt) and I need help writing their multiplied outputs to and output file(output.txt) Why isn't my method showNewArray working? input.txt: 9 3

Array formula [ 12 Answers ]

I have a lookup table and I need a formula that looks at (example) h14 then i14 then looks up the table and returns the value associated with that row. Here is part of my formula, but its lacking something. =IF(h14<0.01," ",LOOKUP(h14,$A$368:$A$711,$G$368:$G$711)) Can anyone help, please....

Array controller [ 1 Answers ]

Have 4 drives in array. Three show as 1 logical; one shows as unallocated. How do I extend the unallocated to the logical.

An array [ 1 Answers ]

How many ratings do you wish to enter? 10 Rating #1: 9 Rating #2: 5 Rating #3: 9 Rating #4: 2 Rating #5: 11 Invalid entry, score must be in range of 1 and 10; try again. Rating #5: -1 Invalid entry, score must be in range of 1 and 10; try again. Rating #5: 8


View more questions Search