Easy question about parts of this code

Code: The purpose is to find a character in a string, and report how many times the character occurs in the string. Basically the program does looking and counting. The code is complied and working well, but my goal is to make it as short as possible, if you can just write a program does the same job in no more than five lines, i will be very appreciate if you share your idea with me.
public class CharFinder{
public static void main(String args[])throws java.io.IOException{
String content;
char target;
int fromIndex = 0;
int foundIndex;
int count = 0;
content =("hello world, i am a boy, and i need help.");
System.out.print("Enter the character to be counted: ");
target = (char)System.in.read();
for (int i=0;i<=content.length()-1;i++)
foundIndex = content.indexOf(target, fromIndex);
if (foundIndex >= 0)
count++;
fromIndex = foundIndex + 1;
System.out.println(" '" + target + "' occurs " + count + " time(s)");
Question:
1.what does string.indexOf do?
2. what are fromIndex and foundIndex 's jobs in the code? in another word, what are they doing in the code?
3. I have to put it in a method, like public void charFinder(), but it cannot compile cuz of throws java.io.IOException, the compiler always says it needs ; at the end..........i can't understand the problem.
Thank you so much if you can answer them.

I think the from index counts how many letters are from the index... and the found are the letters that were found, and the +1 tells it to go on to the next letter to see if it should send that letter back to you.... your third question, the compilers always say you need stuff, adn when you find a problem it has ntohing to do with what it says... my suggestion is just look for something that might be out of place.

Similar Messages

  • Easy question about Reformatting

    Hello all,
    I am trying to reformat my HD after I have deleted Windows XP off of a partition. The reason for this is an upgrade to Vista and a larger allotment of HD space. My question is:
    I am using Backup v3.1.1. (v369) and I have FULL backup files of my Home folder, and my Music folder (as backup for my backup) for all my iTunes libraries. These are located on a portable HD. Are these the correct files to have backed up in order to have my MAC the way it was before I started the process? If so, then once the reformatting is complete, how do I get it all back onto my MAC permanently? Will all my apps and tweaks work as before?
    I am sure this is a simple question, however, I have never had to do this with a MAC, and I want to make sure I have all bases covered before I begin this. Any other comments or advice would be greatly appreciated.
    Thanks All!

    You call this an easy question ???
    Just messin with ya
    Your home folder is the most important folder containing your music, documents, preferences etc. but a lot is also stored in the system folder and library folder outside your home folder, if you want to be ensured of an exact copy of your current system the best way to go at this is to clone your system partition.
    The app i use for this is carbonCopyCloner
    http://www.bombich.com/software/ccc.html
    To add to this.. i've heard there is software for the mac that allows you to make adjustments to the size of your partitions without having to format the drive, i don't know the names of these products but i do know that it's very risky to use them, if you decide to use an app like that make sure you have proper backups of everything just in case it goes wrong.
    Message was edited by: Pr0digy V.

  • Quick (hopefully easy) question about rotating video...

    I'm going to be shooting some video soon that I will later be editing with FCP. I'm going to shoot the video on a Canon Vixia HF10 (AVCHD) camcorder.
    In the situation I'll be shooting, with the mount I'll be using, it would be much easier for me to shoot this video with the camera fully upside-down.
    If I shoot the video fully upside down, can I easily rotate it 180 degrees in FCP with no loss of quality?
    Thanks!

    An interesting thing about video that is shot upside down is the ballistics of the camera movement can be weirdly disconcerting. For instance, if it's a helmet- or wing-style mount, pans and tilts just feel odd.
    As Eric suggests, flipping the image 180 degrees is easy but practice and evaluate.
    bogiesan

  • Easy question about objects

    why with this code;
    private Scanner x;
    public void openfile(){
    try {
    x = new Scanner(new File(chinese.txt));
    why do you say x is a variable at private scanner x and then make x an object? why do both variable and object? the code is from http://www.youtube.com/watch?v=3RNYUKxAgmw
    Edited by: 980099 on Jan 19, 2013 4:30 PM
    Edited by: 980099 on Jan 19, 2013 4:38 PM
    Edited by: 980099 on Jan 19, 2013 4:42 PM

    why do you say x is a variable at private scanner xThe code doesn't actually say it's a variable, but it is. It is a reference of type Scanner. As it isn't initialized in the declaration, its initial value is null.
    and then make x an object? It doesn't. it creates a new Scanner instance and then assigns the reference to 'x'.
    why do both variable and object?You should now be able to see that the question is meaningless.

  • Question about performance in a code.

    Hi experts...
    I need to make a program to make a backp of one table and the a restore.
    The performance of this code is fine?? The tables contain a lot of records!
    PARAMETERS:
              p_backup    TYPE c AS CHECKBOX,
              p_rest      TYPE c AS CHECKBOX,
              p_del       TYPE c AS CHECKBOX.
    SELECTION-SCREEN END OF BLOCK bl2.
    IF p_backup IS NOT INITIAL.  "Cuando se seleccione para hacer backup.
    *Data Selection:
      SELECT mandt bukrs day_a racct prctr per_day average agregate agregate_m accumulate average_m day_exe
        FROM zavg_bal_table INTO TABLE t_avg.
      INSERT zavg_backuptable FROM TABLE t_avg.
    ELSEIF p_rest IS NOT INITIAL.  "Cuando se seleccione para hacer restore.
      SELECT mandt bukrs day_a racct prctr per_day average agregate agregate_m accumulate average_m day_exe
        FROM zavg_backuptable INTO TABLE t_avg.
      INSERT zavg_bal_table FROM TABLE t_avg.'
    ENDIF.

    Hi,
    you are taking a lots of records at one time, just split your results by adding "where" clause, here are a few examples of split:
    - by mandt             (very few splits, lot of records)
    - by day                
    - by initial name     (lot of splits, few records)
    procedure:
    read all mandt's into itab, loop itab doing select and insert
    NOTES:
    - of course splits and quntity of records depend of each table.
    - I suppose that lot of splits with few records are the best choice.
    best regards.

  • Very easy question about variables

    Can I convert float-variable to String-variable?

    Hi, a very easy way to convert almost anything is
    called "typecasting". It might sound difficult, but
    it isn't.
    You use it like this example
    > String outcome;
    Double input;
    input = 3.54789654587;
    Output = ""+input;
    That's not casting. It's implicit formatting.
    What it does is making an empty string and pasting
    your number behind it. VERY easy! You can do this
    with allmost every type of variables.What it's doing is creating a StringBuffer, appending an empty string to it, then appending the result of calling toString on the Double, which is itself a String. (Though things change a bit in jdk1.5.) It works because StringBuffer.append has versions for each primitive type, and toString exists for all Objects.
    One problem is that it's not efficient -- you're doing a lot of work behind the scenes to do something that can be done much more simply. But the bigger problem is that it's using operators in a roundabout way and with implicit results. So it's sort of a hack. "+" is the append operator for Strings (well it actually comes down to an implicit method call, or several). Putting the double on the right side of that also causes an implicit format. So you're implicitly formatting a value, and then appending it to nothing, to get a result. You're not actually meaning to append, you're meaning to format, but you're using an append operator.
    The more straightforward way to do it is simply to explicitly format it, using the methods already shown on this thread, or using java.text.DecimalFormat.

  • Question about parts compatibility G5-Mac Pro

    Hello! Thanks to anyone that has some insight for my question
    I have a loaded G5 powermac and am wanting to make the switch to Mac Pro for some time now. I have 4gigs of RAM and 2 400gb HDD's in my G5. Would I be able to use any of that in the Powermac? Or is it all incompatible now?
    Thanks for any responses...

    So the RAM will work as well? The drives are SATA.
    Well a few reasons for upgrading are that my apple care will soon expire, about 6 months left and I cant renew it ( I wish I could). So if something does finally break down on me, I would be throwing money at it to fix. Plus I would love to run Parallels and BootCamp and just get into the next generation of mac computing. With leopard coming out and all things advancing...i already feel left behind! haha...the marketing demons have me.
    This powermac is by no means obsolete and more than fulfills my needs. Settling for a macbook pro would be awesome...but looking at some of the refurb mac pro's I was thinking I could super fuel it with my current G5 parts.
    Thanks for your replies, gurus!

  • Easy Question about resizing video

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    In my old program "Premiere', to resize and move a video around was very easy. You could adjust the scale and X-Y values numerically, or you could use a Free Transform like in Photoshop. Simply dragging bounding boxes for size and aspect and also dragging the clip to decide it's location.
    The only way I know how to do this in FCP is I double click a clip in the sequence, it loads into the viewer, I go to the Motion Tab and then I can adjust the Scale, which is cool. But then I'm left with the Distort section to adjust position (and aspect if need be). In the Distort section there are 8 numeric fields of info to figure out and fill out just to get one clip in a different position correctly.
    I'm thinking there must be another way to adjust the location (or aspect) of a video clip without spending a bit of time on exact coordinates, I want to eye-ball where I want the clip to go and simply move it there. Is the Distort feature the only way to do this? If not, which is the fastest way to move and change the dimension of a clip.
    Thanks for reading, I hope there is another way, I'm not use to these calculations and they're slowing me down.
    Monty

    I searched 'Resizing Video' and there was too many unrelated results to a really simple question.
    That's because it's not a simple question at all and yet every one of those threads was related to the OP's question. As you discovered, there are lots of ways to interpret "resize," during capture, editing, effects, output, viewing, encoding, printing. But the solution was even simpler than you thought. All you had to do was open the manual or the online help system. Start taking the manuals to the gym with you. FCP is not Premiere. You're going to hate FCP, you're going to love FCP but it will never behave like Premiere beyond the elements of the functional paradigm. Forget Premiere.
    bogiesan

  • Easy question about JScrollPane issue

    The problem is I do not understand why it is not possible, or what I am doing wrong to not be able to initialize a JScrollPane with a variable and call it later, real easy to see in the code below.
    NOTE! I CAN use scrollbars, but only without initializing first, am just trying to understand how to properly do this with initialization or if it is not possible.
    Thank you!!!!
    just look for the First 3 commented sections with stars ******
    import java.awt.Container;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class SquareIntegers extends JApplet {
         // set up GUI and calculate squares of integers from 1 to 10
         public void init() ///all variables below are LOCAL, because used only in "init()" if needed elsewhere make above in the CLASS
                             //OR SAVE VALUES between calls to the class's methods
                // get applet's content pane (GUI component display area)
              Container container = getContentPane();
              container.setLayout(new FlowLayout());
              //creaing a layout because I wanted to add a scroll pane
              //container.setLayout(new BorderLayout());
              // JTextArea to display results
              JTextArea outputArea = new JTextArea(8, 8);
              // JScrollPane myscrollbar = new JScrollPane( outputArea ); //********************this is line 27 why does this along with line 33 NOT work????????
              // attach outputArea to container
              container.add( outputArea);
              //container.add( myscrollbar); ******************************this is Line 33 why does this along with line 277 NOT work????????
              container.add(new JScrollPane( outputArea ));//***********this is Line 34, if I comment out 27/33, and just use this, scrollbars
                                                                     // work correctly, but I have heard/seems better to "initialize variables first"
              int result; // store result of call to method square
              String output = ""; // String containing results
              // loop 10 times
                   for ( int counter = 1; counter <= 10; counter++ ) {
                   // calculate square of counter and store in result
                   result = square( counter );           //***********************uses the CUSTOM method from line 44
                   // append result to String output
                   output += "The square of " + counter +
                   " is " + result + "\n";
                   } // end for structure
         outputArea.setText( output ); // place results in JTextArea
    } // end method init
         // square method definition...***** This is a CUSTOM method creation..... if "Math.sqrt" was used, we would not have to do this
         public int square( int y )
         return y * y;      // return square of y this is RETURNED to the statement in "init()" that originally invoked the
                             // "square()" method - in this case line 32, where RESULT invoked the METHOD, so "result" gets the value of RETURN
                             // if it were "public int square()" that means the method does NOT return a value
    The general format of a method definition is
    return-value-type method-name( parameter-list )
    declarations and statements
    including "return;" or "return EXPRESSION;"
         } // end method square ALL METHODS must always be created inside the CLASS definition, as this one is... notice the closing
              // CLASS bracket below
    } // end class SquareIntegers

    Thank you!!!
    I think I understand...... since the JScrollPane already assigned itself to the JTextArea....
    when "adding" to the parent container, the only necessary component to call was in fact the JScrollPane with the container.add( myscrollbar); I do not know if this is correct, but I thank you for your help, because this definitely confused me, back to studying :)
    I have it 100% operational, just posting this to say thank you that it worked, and it will help further my and possibly others understanding of this.

  • A question about reading tomcat source code

    Hi, everyone!
    I just saw the tomcat source code, there is a method named "await" in StandardServer class. The comment of this method decribe that this method will wait util a proper shutdown command is received.
    I'm confused about it after read this method.
    In my opinion, this method create a server socket on port 8005 by default, and wait for "SHUTDOWN" string to only close the server socket which is listening on port 8005.
    But I think this method is supposed to close all the server sockets which are listenning for client's request and belong to this server when port 8005 received "SHUTDOWN" string.
    Thank you in advance.
    Edited by: Garrett.Li on Oct 17, 2007 9:18 AM

    about reading tomcat source code i cant get you man,

  • Easy question about 'javac'...

    Yeah, at school, we're so used to using a program like CodeWarrior or NetBeans to do all our programming with. However, here at home, I'm trying to code simply in Notepad, and I'm having a little trouble.
    Basically, I'm getting the NoClassDefFound error. The problem is, though, that I can't actually COMPILE the .java file I wrote in notepad - whenever I try to use the 'javac' command, it gives me an error saying it's not recognized as an external command, blah blah blah. So, there's no .class file.
    Yeah, before this, I had downloaded the runtime environment, and it all went fine, but there still isn't any 'javac' command. :/

    You know how states are always debating whether we (Americans)
    should have the ten commandments carved in stone in front
    of our courthouses? - or something like that...
    Well i think someone needs to carve the god-d@mned classpath
    instructions beside the heads at Mt Rushmore, lol.
    Darkslime, dont feel bad everyone has this problem when they
    start (at least the people that dont read the installation instructions).
    This is what you do.
    Install the SDK (not the JRE)
    Take note of the installation folder.
    Recent installations (1.5) seem to be in:
    C:\Program Files\Java\jdk1.5.0_06\
    Find the \bin folder. it contains the "javac.exe" and "java.exe".
    these are the 2 exes responsible for compiling and running
    java programs.
    the final path should be:
    C:\Program Files\Java\jdk1.5.0_06\bin
    go to MY COMPUTER
    right click
    go to PROPs
    ADVANCED tab
    ENVIRONMENT VARIABLES button
    Under SYSTEM VARs:
    "CLASSPATH" - i keep this empty
    "PATH" - add your installation path
    (i.e.: C:\Program Files\Java\jdk1.5.0_06\bin )
    make sure to add a semicolon " ; " to separate it from the last entry.
    SAVE all of this.
    when you compile "cd" into the directory your project is in.
    try compiling. if it doesnt work try:
    javac -cp . Program.java
    and
    java -cp . Program
    NOTE: you can add other folders to the classpath by using a
    semicolo ";" ....
    java -cp .;Folder1;Folder2 Program
    NOTE: the " . " means "this folder"
    If this doesnt work read the BILLIONS of threads about this
    subject all over these forums and the net.
    Good Luck
    oh - and for gods sake use TextPad and not NotePad.
    TextPad has a "compile" button for Java.

  • Easy Question about end jumps

    Here is my menu lay out. Three buttons.
    Play all (Want it to play enire movie)
    Play part one ( Play up to track 6 and return to menu)
    Play part two (Play from track 7 to end)
    Can someone please tell me how to do this correctly? What am I doing Wrong

    Hi Deon - it's hard to say what you are doing wrong if you don't tell us what you are doing!
    What I would do to set this up is place all the footage into a single track, set markers between each section and use stories to define which chapters play when each button is pressed. Your 'play all' button would point to the track itself. Your 'Play part 1' button would point to a story container, inside which I would place chapters 1 to 6. Finally, the remaining chapters would be in a second story and this would be the button target for 'Play part 2'.
    You do not need to have the assets in separate tracks at all - if you want to play a single clip it can be in a single story with just one chapter marker in - each story can have an end jump setting to return back to the menu...
    Hopefully this will help get you on the way, but if not please give as much info about what you have already done so we can start to troubleshoot it with you.

  • Ok. quick and easy question about my Zen Vision

    i'm thinking that my zen can no longer have anything added to it, although there is about 5 gbs worth of space left. it sucks has sucked for a while, but i'm trying to get over it.
    my brother noticed that in the bottom of it, the part where it connects so you can make transfers and stuff, is bent. i tried unbending it but that didn't work.
    and when i connect it to my comp, it says "overload" and my comp freezes for a bit.
    so that's a sign to get another mp3 player right? it's a shame that this happened. he thinks i was too rough with it.
    i admit that i have spent some time pushing it in when it wasn't properly fitting. but i didn't "see" it then. now looking back, i kinda laugh.
    btw, there are no shops around here to repair the bend to the best of my knowledge..actually, maybe Weiss Hardware...just maybe.

    Yes. LOL You word it so much nicer!
    lol...
    if customer support actually does help, for a nice price, you will be -my new saviour-!
    (My music is literally my life.)
    OK. I checked there. They have an option of support (while the warranty is still good) and another option (that's non-technical).
    I got my first Zen Vision (30 GB) March 2007. Then a replacement (this one) in May 2007. Is it still covered? I have my doubts. :P?

  • Quick Easy Question About N580GTX-M2D15D5 Bios

    Hey guys!!
    I just have a real quick and easy (i suppose) question!
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly since the bios date and version remained the same?
    Thanks !

    Quote
    I had bios version KH0, and MSI live update found KH1, i downloaded and flashed successfully (DOS window said please restart and press any key to exit) so i did, restarted my computer, and MSI live update utlity and gpu-z and MSI afterburner are all reporting the same bios version i had with the KH0, version 70.10.17.00.01 & date November 09, 2010
    Quote
    version 70.10.17.00.01
    that's suppose to be, this is the version of the both bioses
    Quote
    & date November 09, 2010
    this is GPU release date, not BIOS date
    Quote
    MSI live update is not picking up the update again, so my question is, how do i know if it flashed correctly
    Get this: https://forum-en.msi.com/index.php?action=dlattach;topic=147603.0;attach=7931
    extract it somewhere, then run info1 , and look for the last line
    Quote
    since the bios date and version remained the same?
    they are not the same, your looking the wrong stuffs

  • I have questions about DNS: Is this a DNS LOOP?

    Hi , everyone:
      I've read some text about the Domain Name System, And found something I can't understand:
      Many Text Say like this: 
      Suppose the resolver want to get the ip address of the domain: www.example.com, The DNS Query Process looks like
      1. The Resolver asks one or more of the ROOT-SERVERS
      2. The ROOT-SERVERS answer to the client that www.example.com is managed by the GTLD-SERVERS, and ROOT-SERVERS Gives some additional records to the Resolver about the ip address of those GTLD-SERVERS
      3. Resolver asks the GTLD-SERVERS about the domain: www.example.com
      4. The GTLD-SERVERS tell the Resolver to ask the IANA-SERVERS again , and again tell the Resolver about the ip address of the Name Server of IANA-SERVERS
      5. Now the Resolver go on asking the IANA-SERVERS about the domain: www.example.com , NOW the IANA-SERVERS answers the Resolver about the ip address of www.example.com
      My First Question is:
      Does Resolver Relay on the ADDITIONAL SECTION?
      Now Suppose I have two domains: example.com and example.org
      And i have registered my own NameServer: ns.example.com and ns.example.org
    Now I go to the registrar and change my DNS as follows:
    example.com  => ns.example.org
    example.org    => ns.example.com
    Then the resolver asks the www.example.com again, In my opinion , the process my looks like this:
    1. Resolver asks the ROOT-SERVERS of the domain www.example.com
    2. ROOT-SERVER answers that the Resolver should ask GTLD-SERVERS, and tell it the ip addresses of those GTLD-SERVERS
    3. Resolver now asks one or more of the GTLD-SERVERS ,
    4. The GTLD-SERVERS answers the Resolver that he should ask ns.example.org , but the GTLD-SERVERS does not know the ip address of ns.example.org , because the ORG domain is not managed by them.
      Then the Resolver must know the ip address of ns.example.org first if he want to resolve www.example.com
    5. Resolver asks the ROOT-SERVERS of the domain ns.example.org
    6. ROOT-SERVERS tell him to ask a0.org.afilias-nst.org. .... and give hime some additional records
    7. Resolver asks a0.org.afilias-nst.org
    8. a0.org.afilias-nst.org tell him to ask ns.example.com, because as HE Knows , it's the name server of example.org , But HE does not have any additional records about ns.example.com because the COM domain is managed by GTLD-SERVERS..
      Then the Resolver must know the ip address of ns.example.com first if he want to resolve ns.example.org ?
    9. Resolver asks the ROOT-SERVERS of the domain: ns.example.com
    10. ROOT-SERVERS tell hime to ask GTLD-SERVERS
    11. Resolver asks the GTLD-SERVERS about the domain: ns.example.com
    12. GTLD-SERVERS tell him to ask ns.example.org..
    LOOP...
    I don't know if my knowledge is right. My Second Question is:
    As I have register my own NameServer: ns.example.com , GTLD-SERVERS has the records of ns.example.com in it's database, But when I ask him ns.example.com , Why He tell me to ask ns.example.org ? Why not just answer me that he has the ip address of my NameServer?
    Hope some one explain it clearly. Thanks

    I'm in the same position, the store said they didn't know of any new release, so i bought my macbook pro to find out about mountain lion. I really hope that i'm not going to pay for the upgrade. New to apple, also last month bought my Ipad 3, really thought that Airplay would have been on my book pro, nope, waste of time.........need that update to use it. Back i the box then, get the windows 7 ultimate pro back out until then.

Maybe you are looking for

  • Problem when upgrading to 11.1.3.8

    I was importing a large file into iTunes (2 hour audio clip called "1001"), when I received the download update dialog.  I did this, but after downloading the installation process began and closed iTunes.  Everything seemed to upgrade with the progra

  • "Best Practice" steps for creating & preseving video quality

    I would like help in understanding the "rules of the trade" when it comes to video quality. I have been converting old VHS video tapes using my Sony DV camera...importing them into iMovie 6HD (mainly because I read that the quality is better in imovi

  • Case front connections ms6577ver2.1 Please

    I have a msi ms 6577 motherboard(ver2.1) Which will be the center of my first build computer. Could anyone please show me how to connect the tower case connections to the motherboard

  • Installing apex 3.2.1 gives upgrade error

    Installing apex 3.2.1.00.10 on windows database (previous version on database is 3.0 or earlier) using p8548651_11106_GENERIC.ZIP when I execute apxpatch.sql I get error: it issues command: execute dbms_registry.check_server_instance; and that errors

  • Safari won't open at all. Any suggestions please?

    SSafari won't open any web pages. Wifi connection good. Any suggestions, please?