I know this is easy.... but

i dont really understand recursion all that well.
Im not sure but i think that im correct about setting largest to 0, and i gotta create a base state using an if statement correct?
And then following else statements to index through the array?
Is this the right course of action regarding the code i posted below. (maxValue method)
public class Lab10
    public static void main(String[] args)
        int[] a = {35, 49, 3, 35, 49, 9, 12, 35, 49, 12, 30, 50, 67, 78};
        print(a);
        int largest = maxValue(a,0,a.length);
        System.out.println("The largest value in the array is "+ largest);
    private static void print(int[] list)
        for(int i = 0; i < list.length; i++)
            System.out.print(list[i] + " ");
            if ((i+1)%10==0) System.out.println();
        System.out.println();
    public static int maxValue(int[] list, int startIndex, int endIndex)
        int largest = 0;
        if(     ){
        else{
}

I didnt quite understand what u told me before.
Recursion is all about the method calling itself right? i kinda took this approach but its not eaxctly doing the job. Can u tell where it went wrong?
public static int maxValue(int[] list, int startIndex, int endIndex)
        if ( startIndex <= 1 ) {
            return list[0];
        else if ( list[startIndex-1] > maxValue( list, startIndex-1, endIndex ) ) {
            return list[startIndex-1];
        else {
            return maxValue( list, startIndex-1, endIndex );
    }

Similar Messages

  • Goodnight gracie, I know this is trivial but why?

    I know this is trivial but in System profiler in the syncservices log i find this, or variantys thereof:
    2011-06-13 20:45:44:432|SyncServer|1994|110fd0|Server|Info| Goodnight, Gracie.
    I think it a message  when the mac goes into sleep mode. But why 'Goodnight Gracie' Apparently it was a catchprase used by George Burns at the end of his radio show, but does anyone know who or why it was included in this log message?
    mike

    Someone may, but it was put in there by one of the programmers as a joke.

  • TS4079 i know this sounds weird but i went to Cleveland from florida and when i returned Siri has an australian accent. any ideas?

    i know this sounds weird but i went to Cleveland from florida and when i returned Siri has an australian accent. any ideas?

    Well you can't use it. The iOS 7 Activation Lock is pretty secure and you can't bypass it.

  • I know this sounds repetative, but one more time.. HELP?

    i know there have been dozens of posts about the loss of ones input device to import video after the upgrades of OSX and the the upgrades of FCP... i also rmember a site tha has all these questions answered... where is the sight.. or who do i chat with about getting my DV deck to get recognized by FCP at startup..
    thank you

    ASSUMING that you have FCP 5...
    you HAVE to have this:
    http://www.apple.com/downloads/macosx/video/fcprescue.html
    It's a sweet little app for deleting, saving and restoring your preferences.
    I am guessing that in the upgrade your prefs got tweaked or QT did some finkydinky, there was an old post that referenced FCE, but that may help you...
    The workaround is to download Quicktime manually, after removing the "receipts" which indicate that it is loaded. Specifically, I was told to do the following:
    1. Navigate to Library -> Receipts on your main drive (not from your personal folder).
    2. Remove all files of the form QuickTime*.pkg, where "*" is a version number. E.g. QuickTime600.pkg, QuickTime650.pkg, Quicktime700.pkg and QuickTime701.pkg. This simply tells your system that those packages are not installed.
    3. Go to http://www.apple.com/quicktime/downloads and click on the "download Quicktime" link. DO NOT USE THE AUTOMATIC UPDATE UTILITY. Download QuickTimeInstallerX.dmg. Double click this file (probably on your desktop) and then invoke the installer by double clicking QuickTime701.pkg.
    4. After your computer reboots, you should be able to restart FCE and see your camera.
    let me know...
    N

  • I know this Is popular, but PLEASE HELP!

    I'm just getting ready to start my very first semester in college, and its time for me to buy a laptop. Here are some of my concerns, hopefully somebody on here can help me decide on which one to get, i'm looking to go buy one tomorrow!
    Pros and Cons about getting a MBP vs. MBA?
    If i don't use the cd drive, and end up getting a MBA, can it handle just as much memory as the MBP?
    What else can somebody tell me? Best battery life, best screen resolution, my spending limit is right about 1600...
    Thanks!!

    Jacobcurtis25 wrote:
    Heres another thing, with spending the same amount of money, i can double my harddrive and memory...
    True. But do you need that much? Find out. Because given clouds, given what people keep on phones, on-line, on external drives, you may not need as much as you think. My point being, don't panic about space unless you know you really need plenty of it--and need everything on tha laptop at all times. And keep in mind that 8gb RAM (for MBA--definately go for that) with SSD is going to be very fast indeed compared to a regular HD. Also, you can put more on SSD than on an HD.
    In the end, both MBA and MBP can give you enough power, memory, etc. to do the job. Obviously, if you have limited funds, that will inform. And if you have requirements from the school, that also will inform. But you haven't given us either price requirement nor memory (HD) requirement. So we can't knock one off because it costs too much or won't give you that much HD (remember, you can get up to 512gb HD on the MBA--if you can afford it).
    Two things I recommend:
    (1) Find out how much HD you need. Really need minimum for what you're studying and going to be doing. If you really need lots of HD, then it's decided. Go Pro. If you don't need as much as you thought, then MBA is still in the running.
    (2) Play on both. What's most important is that you love your computer. If you love your computer, you'll enjoy working on it. If you don't like your computer, you won't enjoy working on it. The two have different feels--pick the up, weigh them, type on them. The computers may make the decision for you.

  • Compilation problem with JSP: i am sure this is easy but cant figure out

    this is my jsp file:
    <@ page import="java.sql.*, com.simpleneasy.*" errorPage="error.jsp"; %>
    <jsp:useBean id="c" class="ConnectionBean"></jsp:useBean>
    <html>
    <%
         String sql = "select * from test;";
         ResultSet rs;
         c.establishConnection();
         try{
              rs = c.executeQuery(sql);
         }catch (SQlException ex){}     
         while (rs.next()){
         %>VALa is <%= rs.getInt("val")%>
         <br>Valb is <%= rs.getString("val2")%><%
         closeConnection();
    %>
    </html>
    located in tomcat416/tomcat/webapps/simpleneasy/jsp
    ConnectionBean.class is located in tomcat416/tomcat/webapps/simpleneasy/WEB-INF/classes/com/simpleneasy
    here is the sample of error that i am getting.. there are a lot more but dont want to paste the whole thing here:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 1 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:42: cannot resolve symbol
    symbol : class ConnectionBean
    location: class org.apache.jsp.testdb$jsp
    ConnectionBean c = null;
    ^
    An error occurred at line: 1 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:44: cannot resolve symbol
    symbol : class ConnectionBean
    location: class org.apache.jsp.testdb$jsp
    c = (ConnectionBean) pageContext.getAttribute("c", PageContext.PAGE_SCOPE);
    ^
    An error occurred at line: 1 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:47: cannot resolve symbol
    symbol : class ConnectionBean
    location: class org.apache.jsp.testdb$jsp
    c = (ConnectionBean) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "ConnectionBean");
    ^
    An error occurred at line: 3 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:60: cannot resolve symbol
    symbol : class ResultSet
    location: class org.apache.jsp.testdb$jsp
         ResultSet rs;
    ^
    An error occurred at line: 3 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:64: cannot resolve symbol
    symbol : class SQlException
    location: class org.apache.jsp.testdb$jsp
         }catch (SQlException ex){}     
    ^

    first of all thanks for helping ..
    i re wrote the code as you suggested like this:
    <@ page import="java.sql.*, com.simpleneasy.*" errorPage="error.jsp" %>
    <jsp:useBean id="c" class="com.simpleneasy.ConnectionBean"></jsp:useBean>
    <html>
    <% String sql = "select * from test";
         ResultSet rs = null;
         c.establishConnection();
         try{     
              rs = c.executeQuery(sql);
              while (rs.next()){        
              out.println(rs.getInt("val"));
              out.println(rs.getString("val2"));
         }catch (SQlException ex){   }
         finally{      c.closeConnection();   }
         %>
    </html>
    but now i am getting this:
    org.apache.jasper.JasperException: Unable to compile class for JSP
    An error occurred at line: 3 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    [javac] Compiling 1 source file
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:59: cannot resolve symbol
    symbol : class ResultSet
    location: class org.apache.jsp.testdb$jsp
         ResultSet rs = null;
    ^
    An error occurred at line: 3 in the jsp file: /jsp/testdb.jsp
    Generated servlet error:
    /usr/tomcat416/tomcat/work/Standalone/localhost/simpleneasy/jsp/testdb$jsp.java:67: cannot resolve symbol
    symbol : class SQlException
    location: class org.apache.jsp.testdb$jsp
         }catch (SQlException ex){   }
    ^
    2 errors

  • I know this is basic but I am lost

    I have not used DVDSP in a while (I am using DVDSP-4) so I am a bit fuzzy. I have created the project and set the first play to menu-1. When I play the simulator it plays the first play but at the end of the first play does not jump to my main menu it just repeats the first play.
    I recall that prevously this connection was automatic once first play was assigned.
    What am I missing? How do I make the connection from first play to my main menu?

    Take a look here http://dvdstepbystep.com/returnmenu.php and set connection for the jump from one to another, connections are not automatic usually

  • I Know, this is stupid, but how do I add a scanner?

    I'm a new convert to Apple. Please be gentle. I knew how to add peripherals with Windows, but I feel like a child now with this iMac. I just need to "add hardware." Am I missing something? I just want to add a scanner...

    Hi Rick
    Just to add to what elmac say's!
    The software disk that is included with the scanner may not be up to date, you may have to go to the "Manufactures Support Site" and download the latest update.
    Examples:
    [Epson Support|http://www.epson.com/cgi-bin/Store/support/SupportIndex.jsp?BV_UseBVCoo kie=yes]
    [HP Support|http://welcome.hp.com/country/us/en/support.html]
    Dennis

  • HT4847 There must be some way of finding out how much storage I'm currently using. One would think that this would easy but apparently not.

    Anyone know how to find out how muh iCloud storage 'm currently using?

    If you're on a Mac, open System Preferences, and open iCloud option.
    Or if you're on an iOS device, open Settings - iCloud - Storage
    You can see the Total Storage and the Available Storage.
    This should solve your question

  • I know this is Dumb but what is MTP and What does it

    Can anyone tell me why everybody is excited about this MTP issue?

    The v2 firmware update for the Zen Micro and MTP in general allows you to plug your player into any Windows XP SP systems with Windows Media Player 0 on it and transfer music and manage your media. It's makes everything more uni'versal and means you don't need special Creative drivers on a computer before you tranfer files anywhere.

  • I want to convert two image files into strings and than to compare them. This is easy, but how to mention where the difference exist?

    I have two image file in bmp file format. How to convert them into string and to check if they are differnt or same. If different how to mention or find that where the difference exists. This idea have to be extented with video application as well.

    Hi,
    if you have vision, you could use the functin IMAQ Image to Array to have a 2D array of the pixel values.
    You can then compare pixel by pixel; if your images come from a camera, I would recommend to set a treshold of acceptance.
    This is a time consuming solution anyway.
    Alternative methods:
    1) Make a subtraction of the two images, the resulting image will be the difference of them
    2 ) Use IMAQ LogDiff function (operators palette)
    3) Calculate the histogram of both image and compare the histogram reports
    Good luck,
    Alberto

  • I know this sounds ridiculous, but do you have to have Fireworks and Dreamweaver to create a website?

    Many years ago, I had a copy of fireworks and dreamweaver.  It seemed like I only worked with fireworks and created websites, links etc.  Do you have to have both and somehow they work in tandem?    

    My suggestion would be to forget about Fireworks, because the application's development was stopped in May 2013, and no updates are coming its way either. It is dead software, unfortunately. It is already experiencing compatibility problems on the latest Mac OS, for example, and it is only going to get worse.
    To create a simple website, you have two choices: you either learn basic html and css code (as Mylenium suggested), or you use a visual editor.
    I have a feeling you veer towards the visual editor solution, so here are some options:
    - http://www.softpress.com/freeway-express/
    - http://www.kompozer.net/
    - Web Design Software by Xara: Xara Web Designer
    - Adobe Muse
    ... or install WordPress through your host (most web hosts offer a one-click install option), choose a nice template from the tens of thousands available online, and start adding content.

  • I know this will sound ridiculous but I have "lost" the arrow key (to go back or forward) at the top on the bar.  I swear I used to be able to just click and arrow to see the previous page and now it's not there.  Help!?

    I know this sounds crazy but I have "lost" my arrow key at the top of the screen to go forward or back.  I'm sure it used to be there but it's really bugging me that I can't find it.  It's a real pain trying to go one page back.  Help?!

    If this is Safari that you've lost the arrows in,  go to Safari > view > show toolbar.
    If the toolbar is present and the arrows missing then right click on the toolbar and select "customize toolbar".
    Drag the arrows or the default set back to the bar.
    Regards,
    Captfred

  • I don't know exactly when this started, but Winamp became my default search and homepage.. The homepage issue was easy, but the search issue is bigger than I expected. It ALWAYS uses Winamp (Powered by AOL) as my default search. Please help. Thank you.

    I don't know exactly when this started, but Winamp became my default search and homepage.. The homepage issue was easy, but the search issue is bigger than I expected. It ALWAYS uses Winamp (Powered by AOL) as my default search. Please help. Thank you.

    reinstall it but make sure to uncheck the box next to "make winamp my default search engine"
    attached is screenshot from the part of installation proces where that checbox should be unchecked
    hope this helps

  • So, I know this has been asked before. But, has anyone heard from Apple?

    So, I know this has been asked before, but I'm just looking to see if anyone had heard from Apple on this at all. The minimum volume on my iPod Classic 160gb is too high, and I can't lower it. (AKA when I kill the volume, I can still hear music).
    I called them today, but the rep was pretty useless. He even dropped the "well, just press pause" line on me. Took him a while to understand that when I'm in bed or studying, etc. the minimum volume is too loud, and I wanted to be able to set it lower.
    The best workaround I've found so far is to buy headphones with their own volume control, but I just can't help but feel that someone shouldn't have to by additonal gear after buying this thing on account of such a basic feature exclusion.
    Anyways, thanks for any help !

    Wow, easy there company boy!
    I've heard all of what you spit up before.  And for your point of "Well, in several cases, people have complained (here in these discussion pages), that they expect the volume to be zero when turned to minimum position" that kind of ties in to why Apple should fix this.
    And yeah....it's pretty much a given that "you and I have different interpretations of what constitues too loud" This is where the option to adjust the minimum volume comes in to play.  (I relly feel bad for you. Honestly. Having to live everyday of your life this way must be just brutal)
    The wording would be pretty simple too. " Be aware there are many instances of the minimum volume being too loud, so think twice before dropping a few hundred bucks on this"
    And, you're right. It is horrible to 'whine' about being ripped off and asking if there is a possible fix for the issue. I really do apologize for that. I should just suck it up and not voice my opinion that this is not fair to consumers, and Apple shouldn't fix a known issue with a product.
    I did reset & restore, I figured that was pretty much implied since I said I spoke to Support.
    And I am not at all surprised that you would say "I - for one - am not surprised that Apple might say, "simply hit the pause button"."  Again, I don't want it on muteReading your post made my eye twitch at least three times.
    This is exactly the reason I was resitant to post on a forum. But, I got a good laugh anyways. Thanks guy!

Maybe you are looking for

  • HDMI Connection Problems

    When I connect my MacBook to my Sanyo 42" HDTV "Please use PC Audio Input for DVI connection" comes on the screen. What do I do?

  • Iphone will not respond after trying to put it into DFU mode while in recovery mode.

    I tried to restore my iphone 4 and recieved error 21 in itunes, while in recovery mode I tried to put it into DFU mode and then it turned off and wont turn back on or be recognized by itunes or pc. I tried doing a hard reset and no luck. HELP PLEASE!

  • My puchased songs wont go onto my ipod

    My purchased songs won't go into my ipod for some reason can somebody help me!

  • Need a Quicker Way to Unarchive...

    Hello All: I have some .tar.gz archives on DvD's that are made for backup. I went to go and open one today and it took forever to unarchive the file. Is there a way to just look at the contents of this file or is there a quicker way to unarchive? Tha

  • How to install 64bit java version

    Dear All, I need config jvm memory greater than 2G because "Account Analyst Report" issue. If I must need to install JAVA version 64bit, how can I do it? Platform is: Oracle Solaris on SPARC (64-bit) Current Java version is: java -version java versio