Quick Question on Arrays.fill() Method

Does this work for a multidimensional array? I've tried and I can't get it to.
          double stuGrade[][];
          stuGrade = new double[3][125];
          Arrays.fill(stuGrade, -1); //Have also tried Arrays.fill(stuGrade[][], -1) error: Cannot resolve symbol
symbol: method fill (double, int)
Have imported java.util.Arrays....
I need to set all values in atleast one row to a negative number. I haven't had a chance to look at vector (is that it?) arrays. So every element may not be populated. Since it is possible for an entry to be zero, I can't use a condition of not equal to zero to determine whether the loop should continue processing or not....
Thank you!

fill(double[] a, int fromIndex, int toIndex, double
val)
Where a is your array.... so really your just missing
your fromIndex and toIndex... no worries.Seeing as how the OP's array is a double[][] rather than a double[], the worries will continue. The fromIndex and toIndex are optional; if he's wanting to fill a single entire array, the fill(double[] a, double val) is fine.

Similar Messages

  • Quick question on Arrays

    I have this bit of code
    public class BubbleSort {
    public static void main(String[] args) {
    for (int st=0; st<args.length; st++){
    int st_to_int = Integer.parseInt(args[st]);
    System.out.println(st_to_int);      
    how can I convert st_to_int to arrays[7] of interger of 7 ARRAYS

    Dear warnerja,
    I tried it but it came up with this error
    BubbleSort.java:12: ']' expected
                        int st_to_int[st] = Integer.parseInt(args[st]);
    ^
    reply to
    If I interpret your question correctly, I think you want something like:
    int[] st_to_int = new int[args.length];
    for (int st = 0; st < args.length; st++)
    st_to_int[st] = Integer.parseInt(args[st]);
    }

  • Very simple and quick question about Arrays

    Hi,
    I have the following code to produce a student grades provessing system. I have got it to store data in the array, i just cant figure out how to add the integers from the row to produce a total. Thats all I want to do create a total from the 6 marks and add a percentage.
    Any help would be greatly appreciated.
    -------------CODE BELOW----------------------
    import java.util.*;
    public class newstudent1_2
    public static void main (String[]args)
    System.out.println ("-----------------------------------------------"); //Decorative border to make the welcome message stand out
    System.out.println (" Welcome to Student Exam Mark Software 1.2"); //Simple welcome message
    System.out.println ("-----------------------------------------------");
    int [][] mark;
    int total_mark;
    int num_students;
    int num_questions = 9;
    Scanner kybd = new Scanner(System.in);
    System.out.println("How many students?");
    num_students =kybd.nextInt();
    mark = new int[num_students][num_questions] ;
    for (int i=0; i<num_students; i++)
    System.out.println("Enter the Students ID");
    String student_id;
    student_id =kybd.next();
    System.out.println("Student "+i);
    for( int j=1; j<num_questions; j++)
    System.out.println("Please enter a mark for question "+j);
    mark[i][j]=kybd.nextInt();
    System.out.print("id mark1 mark2 mark3 mark4 mark5 mark6 mark7 mark8");
    //This section prints the array data into a table
    System.out.println();
    for (int i=0; i<num_students; i++)
    for( int j=0; j<num_questions; j++)
    System.out.print(mark[i][j]+"\t"); //the \t is used to add spaces inbetween the output table
    System.out.println();
    --------------END OF CODE---------------
    Thanks.

    I had to do this same sort of thing for a school assignment but i didnt use an array.
    import java.text.DecimalFormat;
    import TurtleGraphics.KeyboardReader;
    public class grade_avg
         public static void main(String[] args)
              int grade, total = 0, count = 0;
              double avg = 0.0;
              KeyboardReader reader = new KeyboardReader();
              DecimalFormat df = new DecimalFormat("0.00");
         for (;;)
                   grade = reader.readInt("Please enter a grade: ");
              if (grade > 0)
                        total = total + grade;
                        count ++;
              if (grade == 0)
                        avg = total / count;
                        System.out.println("The average is: " + df.format(avg));
                        System.exit(0);
    }output looks like:
    Please enter a grade: 100
    Please enter a grade: 50
    Please enter a grade: 0
    The average is: 75.00

  • Quick question how to wrie entire array in one go without loop

    I have the following loop, which goes around store array and write each element to file one at a time, i have been told that i can do this an easy way by writting the entire array at once. Can anybody tell me how to do this?
    int storeSize = store.getCount();
    for (int i = 0; i<storeSize;i++)
    output.writeObject(store.elementAt(i));

    i believe the method is
    Arrays.fill(
    read the api of the Arrays classPerhaps you should read the API, too, before
    offering advice.eerm, i dont need to read the api because i know this method exists:
    static void      fill(Object[] a, Object val)
    Assigns the specified Object reference to
    each element of the specified array of Objects.I'm sorry, you're absolutely right. Original poster, stop serializing objects
    to that ObjectOutputStream, and instead fill an array with multiple
    references to the same value. Whew, that was a close one, eh mates?

  • Fill method isn't working on arrays.

    I am trying to use(on JDK 1.4) the fill method of util.Arrays class to fill an array. It gives "cannot resolve symbol" error at the line with fill command. What am I doing wrong here ?
    import java.util.Arrays;
    public class arrtest {
    public static void main(String[] args)
    int arr[] = new int[20];
    fill(arr,0,7,1);
    }}

    The fill() method is a static member of the Arrays
    class and hence must be identified as such. Try
    substituting the following line for what you already
    have:
    Arrays.fill(arr, 0, 7, 1);ShaunYup.
    Thanks Shaun.

  • Disabling Quick Fill method menu items

    We are using Quick Fill functionality for Service Request Detail Applet.
    Enabled the 4 method menu items and those are working fine.
    1. ApplyTemplate
    2. SaveTemplate
    3. NewFromTemplate
    4. NewFromLastTemplate
    These methods are based on a vanilla business service 'Quick Fill Service'
    We have to disable(gray out) these method menu items for Cancelled SR.
    Tried to disable the corresponding command's method: 'LaunchNewFromTemplate' by config (CanInvokeMethod) and script, but it is not graying out method menu item.
    Did any one face this issue?
    How to disable (gray out) these Quick Fill method menu items? Please advice.
    Thanks,
    Ramana

    He should be able to use Spotlight to launch Parallels anytime he wants. Unless changed, command-space is the default command to get Spotlight to open. Typing in the name of the program and clicking the down arrow until you select the program and hitting Return will launch the program.

  • Copy Array Quick Question

    Just a quick question.
    Say I have an array A = [1,2,3,4,5]
    B = new int[5]
    I understand to copy the elements of A into B we could use a for loop.
    But can somebody explain to me why you can't just go B = A?
    Does this just cause B to point to A?
    So how do arrays work exactly? Is it like in C where each element is actually a pointer to the data, or does Java copy the data directly into the array element?

    Kayaman wrote:
    JT26 wrote:
    Array A=[1,2,3,4,5] ----> Here A is a reference variable which points to memory locations A[0],A[1],A[2],A[3],A[4] which could not be continueous.Actually no. What you have there is a syntax error. And please don't confuse people by talking about non continuous memory locations. That's simply wrong.And 100% irrelevant for the question at hand.
    >
    B = new int[5] -----> Here B is another reference variable points to an array which could hold 5 elemets.That is correct, basically.
    All the five element holders of B could be physically any where in the memory, thus copying the the elements is done via a for loop.No, Java is smart enough to store arrays sequentially in memory. And the smart way to copy large arrays is System.arrayCopy().Or java.util.Arrays.copyOf.

  • Quick Question: When to use ( ) and when to use [ ] and why the ( *)

    Hi all,
    A quick question that i'm sure is very simple but is slightly confusing me. I've just started trying to learn Objective-C and am a little confused by ( ) and [ ].
    I get that you use the [ ] brackets when you want something specific from an object, i.e.
    [ textField textColor ]
    and that you use ( ) brackets for things like:
    if ( x == y) {
    But I get confused when I see things like:
    NSLog(@"some text here");
    Why does that get ( ) brackets and why is it not [ ].
    Also another point of confusion, creating methods... Why are some methods done like:
    - (void)awakeFromNib
    And others done like (with the additional "*" added):
    - (NSString *)stringvalue
    As I said, I'm sure this is very simple and obvious, but it is confusing me slightly.
    Thanks in advance!

    Adam:
    As you already know, square brackets are used to send a message to an object, so if a object like myObject implements the method -doSomething, you can call it with:
    \[myObject doSomething\];
    The other use square for brackets have is to index C-style arrays, such as:
    aValue = anArray\[10\]; // Get the 10-element of an array
    However, because C-style arrays are rarely used in Cocoa applications (use NSArray instead) you will not see this situation often.
    Parenthesis in expressions are used to group and prioritize, such as:
    x = 10 * (3 + 5); // x = 80
    If () statements use it to delimit the test expression. Same with while (). for () uses it to enclose the limits and increment statements, etc.
    The other important use of parenthesis is in calling a C function:
    result = foo(3);
    means that you are calling the function named foo with the argument 3, and storing the the return value in the variable 'result'. This is different from a message because a C function is not a method of an object. They exist independently of any objects. NSLog() is a function defined within Cocoa but it is not a method. So, you call it with the traditional C function call syntax. Cocoa defines other functions like NSStringFromRect(), which takes an NSRect as argument and returns a pointer to an NSString.
    And that leads me to your last question. Some methods return simple types, like int, float, or void (i.e. returns no value). These methods will have prototypes like:
    \- \(void\)returnNothing;
    \- (int)returnInteger;
    Other methods return pointers to types, like:
    \- (int \*)returnPointerToInteger;
    \- (void \*)returnPointerToAnything; // In obj-C one typically uses id instead of void*
    Returning whole objects from methods has problems and it is better to just return a pointer (the address in memory) instead:
    \- (NSString *)makeAString;
    The method above returns a pointer to an NSString rather than the entire object.
    Good luck with your learning,
    Juan-Pablo
    Message was edited by: Juan Pablo Claude

  • Two quick questions about Library after moving beginning on a new computer

    Hi there,
    I just moved from Windows to Mac, meaning I had to move my iTunes library from the old PC to my new MBA.
    Just a couple of quick questions.
    1. When I started iTunes on my new Mac, in the preferences I directed the media folder to the folder with all my itunes music/podcasts etc, and then I imported the Library XML file.  Is this incorrect? Should I have imported a different file? Should I have used the itl file instead? 
    If so, should I delete the library and start again?  (if this is the case, please suggest the best way of doing this without affecting my media)
    - a kind of sub-question to this one:  some of the media files arent showing up in the iTunes library, but they are in the media folder on the ext HDD.  Is there a way I can find out which ones havent been recognized by iTunes?  Whats the best way of getting them in to my library?
    2. Pretty much half of my podcasts have not been loaded in the new iTunes.  The ones that havent were ones that I subscribed to on my iPhone, whereas the ones that show up in iTunes were ones I downloaded from iTunes.  When I connect my iPhone and sync it with iTunes, will those podcasts show up in iTunes?  Or is there a risk that they will be deleted from my iPhone?
    Cheers,

    The .xml is lacking some information such as ratings, date added, and play count.  Using the .itl includes this information but cannot be imported using the method you did.
    A complete library is everything in the iTunes folder.  By using the method you did you left the artwork behind in the artwork folder on the other machine.
    Selecting the media folder in preferences does not get iTunes to recognize the media.  All it does is tell iTunes to start storing new media in that location.
    Using the method I outlined nothing will be missed (with the exception of WMA) because you aren't rebuilding your library, you are using the one that already exists.
    You don't have to re-copy everything as long as you get the stuff you missed and re-assemble it all as it was before except not on the Mac.
    What are the iTunes library files? - http://support.apple.com/kb/HT1660
    More on iTunes library files and what they do - http://en.wikipedia.org/wiki/ITunes#Media_management
    What are all those iTunes files? - http://www.macworld.com/article/139974/2009/04/itunes_files.html
    Where are my iTunes files located? - http://support.apple.com/kb/ht1391

  • Doubt in working of Arrays.sort method. help needed !!!!

    Hello Friends,
    I am not able to understand output of Arrays.sort method. Here is the detail of problem
    I wrote one program :
    public static void main(String[] args) throws ClassNotFoundException
         Object[] a = new Object[10];
         a[0] = new String("1");
         a[1] = new String("2");
         a[2] = new String("4");
         a[3] = new String("3");
         a[4] = new String("5");
         a[5] = new String("20");
         a[6] = new String("6");
         a[7] = new String("9");
         a[8] = new String("7");
         a[9] = new String("8");
    /* Sort entire array.*/
         Arrays.sort(a);
         for (int i = 0; i < a.length; i++)
         System.out.println(a);
    and output is :
    1
    2
    20
    3
    4
    5
    6
    7
    8
    9
    Question : Does this output is correct? If yes then on which basis api sort an array? I assume output should be 1 2 3 4 5 6 7 8 9 20.
    Can here any one please explain this?
    Thanks in advance.
    Regards,
    Rajesh Rathod

    jverd wrote:
    "20" and "3" are not numbers. They are strings, and "20" < "3" is exactly the same as "BA" < "C"The above is
    ... quote 20 quote less than quote 3 quote...
    but shows up as
    ... quote 20 quote less than quote...
    Weird.

  • Quick question regarding best practice and dedicating NIC's for traffic seperation.

    Hi all,
    I have a quick question regarding best practice and dedicating NIC's for traffic seperation for FT, NFS, ISCSI, VM traffic etc.  I get that its best practice to try and separate traffic where you can and especially for things like FT however I just wondered if there was a preferred method to achieving this.  What I mean is ...
    -     Is it OK to have everything on one switch but set each respective portgroup to having a primary and failover NIC i.e FT, ISCSI and all the others failover (this would sort of give you a backup in situations where you have limited physical NICs.
    -    Or should I always aim to separate things entirely with their own respective NICs and their own respective switches?
    During the VCAP exam for example (not knowing in advance how many physical NIC's will be available to me) how would I know which stuff I should segregate on its own separate switch?  Is there some sort of ranking order of priority /importance?  FT for example I would rather not stick on its own dedicated switch if I could only afford to give it a single NICs since this to me seems like a failover risk.

    I know the answer to this probably depends on however many physical NICs you have at your disposal however I wondered if there are any golden 100% rules for example FT must absolutely be on its own switch with its own NICs even at the expence of reduced resiliency should the absolute worst happen?  Obviously I know its also best practice to seperate NICs by vender and hosts by chassis and switch etc 

  • Quick Question: Setting Render File Location

    Hi all,
    Quick question. I'm guessing with all the disappointment, the answer will be no, but I fully realize that I could have overlooked something so its worth asking!
    In FCP7 (familiar phrase huh?) you could explicitly set a location for render files. I understand that you can save FCPX Events on different drives, as well as your projects, however it appears as if the Render Files are getting saved with a folder which also contains your .fcp project file.
    I ask because I like having my project file on my internal so my Time Machine will pick it up when I have it hooked up, but all of those render files take up loads of space and I'd like that on my external media drive instead.
    Is there:
    a.) A way to tell FCPX to store Render Files in a different location
    OR
    b.) A way to move the Render Files to a different location without screwing up FCPX's ability to recognize the project and load it properly.
    If so, great! If not, I'll send it along as a suggestion among with some others. Other than those overlooked technical aspects, I'm kind of digging the UI of FCPX and background rendering is saving me so much time its not even funny.

    Hi Jorgen
    I spent a bit of time on this today without any success.
    In our studio, it's only me that edits... but I use a laptop and a macpro when things get serious. I have a RAID array tyed to the Macpro, and I access it with my laptop via gigabit ethernet.
    I created aliases, and when I opened FCPX, nothing appeared. I also was not able to change the name of events I created, and while it would write the project name and events to the new aliased directories... when I reopened FCPX the events and projects were missing.
    I then tried symbolic links via the terminal. No luck. I then checked ownership permissions, and made sure the permissions were ignored for the drive and everything was world readable and writable. No luck.
    Have you had a chance to experiment with this yet?
    Thanks

  • Problem accessing results from DataService fill method

    I've set up an application that gets data from a data service
    configured with a java-dao adapter. If I define a DataGrid
    with the
    array populated by the fill method I see the data in the
    grid. Cool.
    So I know I've configured and coded everything correctly.
    However, if I try to access the data with the following code,
    it
    appears my array is empty!
    ray = new ArrayCollection();
    ds = new DataService("assets");
    ds.fill(ray);
    var asset:Asset = ray[0];
    This gives me an index '0' out of bounds error. I've also
    tried
    ray.getItemAt(0) with the same results.
    How do I access and manipulate the results of a fill method
    via
    ActionScript? I'm currently using Beta3.

    Note that it takes time to actually make the dataservice call
    and retrieve the results. Your data won't be available right away.
    After calling fill(), you have to wait for the "result" event of
    the DataService object.

  • Quick Question **PLEASE HELP** .jar file?

    Hey everyone, im pretty new to the java scene but I have a really quick question that hopefully someone can help me with.
    I'm really interested in making a .jar file out of my code. And basically I just want to make one. but i understand there are certain things like main class's, etc. that need to be made in order to make a .jar file.
    So basically Say I opened up a new project in blueJ. I made 1 new class called "main." Inside of it I had nothing for conductors and no variables declaired untill the bottom part where i write my code.
    say i write...
    System.out.println("hello");
    and that is it.
    What steps from there do i do to make a jar file and have it be able to be executed and SEE the "hello" printed somewhere NOT in blueJ??
    (I understand there is something about a "static" method? Im not really sure but if somoene could enlighten me on how to make a .jar file that would be great.)
    Thanks a lot everyone!
    Tom

    I don't know anything about BlueJ, but this section of Sun's tutorial explains how to
    write a program that outputs a single line of text to the console:
    http://java.sun.com/docs/books/tutorial/getStarted/cupojava/win32.html
    Deploying an application as an executable .jar file is covered here:
    http://java.sun.com/docs/books/tutorial/deployment/jar/index.html
    The first two sections - "Using JAR Files: The Basics" and "Working with Manifest
    Files: The Basics" - contain the information you need to understand this process.

  • Quick question (why is this happening)

    i'm working on a draggable background with boundaries and had
    a quick question for you guys that know way more than me about
    actionscript... any help will be greatly appreciated.
    i have a draggable movie clip and set up boundaries for it,
    and they all work except for when you drag the MC to the extreme
    left/bottom corner... the left boundary stops working as soon as it
    hits that direct corner..
    see for yourself:
    http://www.liquid-creative.com/testing.php
    my code is below... any thoughts?

    hm... well I think what you really need to get out of the
    dragging step is the vector of the object when the object is
    ‘released’?
    I suppose you could use the actual startDrag()/stopDrag
    methods to do the dragging work for you and then add on to it.
    Perhaps while the mouse is moving, keep track of (and update) the
    values/vector of where the mouse was 1 ‘movement unit’
    before (1 frame before I presume), then when stopDrag() is called,
    at the same spot, subtract the current vector from the vector
    stored and use the result for calculating inertia.
    (Note that I don’t have flash in front of me so this
    actually coming from my head, -someone may have a better
    method)

Maybe you are looking for