CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2010
    Posts
    2

    Exclamation array assignmnet =(

    hi
    i'm saudi student

    FRESHMEN IN MIS =)

    i have an assignment and i can't get it =(

    the Q IS

    given the following array
    int [] array={10,19,5,1,7};
    write a java program using array to display its data graphically by plotting each numeric value as abar of asterisks (*) as shown in the diagram

    element value histogram
    0 10 **********
    1 19 *******************
    2 5 *****
    3 1 *
    4 7 *******

    I Understand that i need to declare and use for loop
    but i don't know how to convert the value to *

    i want some help please =)
    regard ..

  2. #2
    Join Date
    Apr 2007
    Posts
    425

    Re: array assignmnet =(

    can you show me what a for loop looks like.
    ------
    If you are satisfied with the responses, add to the user's rep!

  3. #3
    Join Date
    Jan 2010
    Posts
    2

    Re: array assignmnet =(

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

    this is what i learn =)

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163

    Re: array assignmnet =(

    OK, so you can use another 'for' loop inside the array loop to print the correct number of '*' for each number. For each number in the array, you want to print the number itself, then the equivalent number of '*' (using the other 'for' loop). Think about how you typed it when you wrote that last message.

    The purpose of computing is insight, not numbers...
    R. Hamming
    Please use &#91;CODE]...your code here...&#91;/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.

  5. #5
    Join Date
    Apr 2007
    Posts
    425

    Re: array assignmnet =(

    now, can you show me how to display a specific value inside of the array.

    If you put those two things together, like dlorde said, you have the answer.

    The biggest part of development you will find is not in the actual code. It never gets very complicated. It is in the thought process and understanding what you are trying to do and how to go about it.
    ------
    If you are satisfied with the responses, add to the user's rep!

  6. #6
    Join Date
    Jul 2009
    Posts
    105

    Re: array assignmnet =(

    try something using a for loop

    when you have your variable declared just do print

    Code:
    for(int counter=0;counter<array.length;counter++){
         System.out.print("*");
    }
    You could do something along those lines but since you are a student i suggest you try other ways of doing it.

    --Alex
    Last edited by Alexz003; January 25th, 2010 at 09:55 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured