Determining number of teenagers living in a street

I'm creating a java program to determine how many people are in a street, and how many of those people are teenagers. The information is gathered from an input file which is featured below.
INPUT FILE*
12 20 13 19 34 80 0 14 75 17 50 1 11 11 30 90 15 16 70 50 -2
CODE*
/* Session7A07.java */
/* Determines number of teenagers living in a street */
import java.util.*;
import java.io.*;
public class Session7A07
  public static void main (String[] args) throws FileNotFoundException
   /* variable declarations */
   int    age,
          people_count,
          teenage_count ;
   File age_file = new File("Session7A07.txt");
   Scanner age_data = new Scanner(age_file);
   age = age_data.nextInt();
   while (age >= 0)
      ++ people_count ;
      if (age >= 13 && age <= 19)
              ++ teenage_count;     
      age = age_data.nextInt();
   System.out.printf ("Teenage Count = %d%n", teenage_count) ;
   System.out.printf ("People Count = %d%n", people_count) ;
ERRORS_
M:\>javac Session7A07.java
Session7A07.java:23: variable people_count might not have been initialized
      ++ people_count ;
         ^
Session7A07.java:25: variable teenage_count might not have been initialized
                 ++ teenage_count;
                    ^
Session7A07.java:29: variable teenage_count might not have been initialized
   System.out.printf ("Teenage Count = %d%n", teenage_count) ;
                                              ^
Session7A07.java:30: variable people_count might not have been initialized
   System.out.printf ("People Count = %d%n", people_count) ;
                                             ^
4 errorsCurrently have 4 errors and would greatly appreciate the help.
Thanks in advance.

redfalconf35 wrote:
int age,
people_count,
teenage_count ;the compiler doesn't like that you declared your variables but didn't initialize them to a valueTo expand on that: Member variables (those declared in the class, but outside of a method) are initialized with a default value if you don't explicitly initialize them. Variables declared in a method aren't given a default value, so if you use them without first setting their value, the compiler complains. Your while loop's body isn't guaranteed to be entered, so there's no guarantee that your variables will be set before use.

Similar Messages

  • To determine number of months

    Is there any function module to determine number of months ,when i give two dates ,ie startdate and enddate .
    thanks in advance.
    ravi.s

    Hi,
    Check this.
    MONTHS_BETWEEN_TWO_DATES
    Laxman

  • Determine Number of Decimal Place using BigDecimal

    I was interested to have the following getNumberOfDecimalPlace function :
    System.out.println("0 = " + Utils.getNumberOfDecimalPlace(0)); // 0
    System.out.println("1.0 = " + Utils.getNumberOfDecimalPlace(1.0)); // 0
    System.out.println("1.01 = " + Utils.getNumberOfDecimalPlace(1.01)); // 2
    System.out.println("1.012 = " + Utils.getNumberOfDecimalPlace(1.012)); // 3
    System.out.println("0.01 = " + Utils.getNumberOfDecimalPlace(0.01)); // 2
    System.out.println("0.012 = " + Utils.getNumberOfDecimalPlace(0.012)); // 3
    I use the following code
        public static int getNumberOfDecimalPlace(double value) {
            final BigDecimal bigDecimal = new BigDecimal("" + value);
            final String s = bigDecimal.toPlainString();
            System.out.println(s);
            final int index = s.indexOf('.');
            if (index < 0) {
                return 0;
            return s.length() - 1 - index;
        }However, for case 0, 1.0, it doesn't work well. I expect, "0" as result. But they turned out to be "0.0" and "1.0". This will return "1" as result.
    0.0
    0 = 1
    1.0
    1.0 = 1
    1.01
    1.01 = 2
    1.012
    1.012 = 3
    0.01
    0.01 = 2
    0.012
    0.012 = 3
    Any solution?

    Please [don't cross-post!|http://stackoverflow.com/questions/2296110/determine-number-of-decimal-place-using-bigdecimal], it's considered rude. If you must do it, then at least link each post so that people can find out which answers you've already got in order to avoid duplicate work on our part.
    Please read [_How To Ask Questions The Smart Way_|http://www.catb.org/~esr/faqs/smart-questions.html].

  • Using MASSG to determine number ranges in NUMKR

    Hi,
    I am trying to get NUMKR to determine number ranges using reason for action(MASSG).  A new business unit is coming onboard and need to keep their existing staff numbers. Therefore two number ranges were set up. 01 for external and 02 for internal.
    A reason for hire action exists with the reason 99 - Data migration.
    NUMKR is set as follows.
    If MASSG = 99 and employee group = 1 then choose number range 01 otherwise if MASSG <> 99 and employee group = 1 then choose number range 02.
    However when running PA40. This does not work and it ends up always picking the otherwise option.
    Has anybody else experienced this?
    Thanks in advance

    Hi David
    There seem to be an error while setting the feature. You are adding another condition of EG=1 in the otherwise & that is probably causing an error. Can you set the feature as follows:
    Country Code = 99 > EG =1> MASSG = 99 --> 01 otherwise 02. And the otherwise that you get at the country code level =02 unless you have other country Molga's defined. Please check that all the employees that you are trying to get into the system initially are EG =1 else it will not work. After creating the feature & ensuring that the feature is error free, activate it.
    Regards
    UR

  • How to determine number of photos I have?

    I cannot find anywhere in Photoshop Elements where it tells the total of photographs I have in my collection.  The old version told this number in the lower right hand corner.  Is there somewhere in this newer version where I can find how many photos I have without having to count them?  Please help.  Thanks.

    Thanks so much Neale!!!
    In a message dated 2/19/2014 7:05:52 P.M. Eastern Standard Time, 
    [email protected] writes:
    Re:  How to determine number of photos I have?
    created by nealeh (http://forums.adobe.com/people/nealeh)  in Photoshop 
    Elements - View the full  discussion
    (http://forums.adobe.com/message/6137888#6137888)

  • How to determine number range for billing document based on company code ..

    Hi Friends!!
    can anybody tell me how to determine number range for billing document based on company code & tax departure country if required??
    Amit...plz help me!!

    Hi Amit,
    1. Define different Billing Document number ranges in  SPRO -> Sales & Dist -> Billing -> Define number ranges for billing docs. (VN01). Make sure that all are internal number ranges.
    e.g.
    NO.  From number To Number    Current number  Ext
    A1   0930000000    0930999999
    A2   0940000000    0940999999
    A3   0950000000    0950999999
    2. Define a Ztable ZNUMB_RANGE as follows
    Comp. Code | Tax departure country | Billing Doc Type | Number Range
    100                IN                               F2                      A1
    200                IN                               F2                      A2
    200                US                              F2                     A3
    3. In user exit RV60AFZZ (USEREXIT_NUMBER_RANGE)
    Read table ZNUMB_RANGE for Number Range with Comp. Code, Tax country and Billing Doc.
    If found pass this number range value to us_range_intern.
    us_range_intern is a standard SAP variable which tells program which number range use to create the current document which is under process.
    Let me know if you are clear.
    Thanks,
    Mandar

  • Getting SkypeIn Hong Kong number while NOT living ...

    Hello,
    I currently live in Japan however I would like to have a HK Skype-In number and I do not plan to live in HK. Is that technically okay?
    I was wondering if I had a HK Skype-In number (while still living in JPN), that would lower my friend's telephone bill who live in HK when he places a call to me.
    Are there any technical problems if I do this?
    Thank you for your time.
    Atsushi

    I have 2 numbers in Hong Kong for many years and have had no issues.
    About Me You can also use a IP Camera as your camera for Skype video Example Instructions

  • How to determine number of records in recordset returned by stored procedure?

    In TestStand 3.0 I am calling an SQL stored procedure where the stored
    procedure returns a recordset. Everything appears to work (I can
    iterate through the recordset and see that the data is valid).
    However, I can not figure out how to easilly determine how many
    records are actually in the recordset. Unlike the 'Open SQL
    Statement' step, in the 'Data Operation' step that actually invokes
    the stored procedure, there is no 'Number of Records Selected' option
    to specify a TestStand variable to accept this value. I know I could
    iterate through the returned recordset incrementing a counter until a
    Fetch fails, but for larger recordsets, traversing the table multiple
    times would be quite time consuming
    . I am hoping to avoid this if
    possible. Is there an easier way to get the number of records in a
    recordset returned from a stored procedure call?
    Bob

    Bob -
    The cursor type of the ADO Recordset object affects whether the number of records can be determined. The Recordset.RecordCount property will return -1 for a forward-only cursor; the actual count for a static or keyset cursor; and either -1 or the actual count for a dynamic cursor, depending on the data source.
    Because ADO does not let me set the cursor type for command objects which is what a stored procedure requires, it is up to the data source to determine the type of cursor and the support for record count.
    Scott Richardson (NI)
    Scott Richardson
    National Instruments

  • Determining Number of Rows in a ResultSet

    Hi,
    Is there an easy way to determine the number of rows in a result set with TYPE_FORWARD_ONLY?

    > > Try ResultSet rs = statment.executeQuery(...);
    if(rs
    == null){ //result set is empty}That is incorrect... it should have read:
    ResultSet rs = statment.executeQuery(...);
    if( ! rs.next() )
    //result set is empty
    you're right!! copy/paste from executeUpdate( ) api documentation about statements....
    "a ResultSet object that contains the data produced by the given query; never null"
    here's the catch though: that will advance your result set, which will throw off your cursor in a while loop (used to parse the results). requires you to reset the cursor before processing the result set.

  • Without looping: Determine number of unique values in a set

    Hi all,
    I was wondering if anyone has any advice on determining the
    number of unique items in a set. For example:
    If I have an ArrayCollection
    public var someData:ArrayCollection = new ArrayCollection([
    {id:"1", color:"Red", value:5"},
    {id:"2", color:"Red", value:"4"},
    {id:"3", color:"Green", value:"17"},
    {id:"4", color:"Red", value:"3"},
    {id:"5", color:"Blue", value:"4"}]);
    What I want returned is just Red, Green, Blue
    but not Red, Red, Green, Red, Blue. Or even better would
    just be a number telling me how many unique values are in the set.
    I've spent hours digging through the asdocs but have not found
    anything that performs this type of analysis and I've typically had
    to resort to endless loops (which can affect performance when the
    data set is large).
    I would appreciate any words of wisdom.

    "shawn.yale" <[email protected]> wrote in message
    news:ghs5lo$fkb$[email protected]..
    > Hi all,
    > I was wondering if anyone has any advice on determining
    the number of
    > unique
    > items in a set. For example:
    >
    > If I have an ArrayCollection
    > public var someData:ArrayCollection = new
    ArrayCollection([
    > {id="1", color="Red", value="5"},
    > {id="2", color="Red", value="4"},
    > {id="3", color="Green", value="17"},
    > {id="4", color="Red", value="3"},
    > {id="5", color="Blue", value="4"}]);
    >
    > What I want returned is just Red, Green, Blue
    but not Red, Red,
    > Green,
    > Red, Blue. Or even better would just be a number telling
    me how many
    > unique
    > values are in the set. I've spent hours digging through
    the asdocs but
    > have
    > not found anything that performs this type of analysis
    and I've typically
    > had
    > to resort to endless loops (which can affect performance
    when the data set
    > is
    > large).
    >
    > I would appreciate any words of wisdom.
    You could use a GroupingCollection with a SummaryRow.
    HTH;
    Amy

  • Determining number of cursors needed !!!

    Hi all,
    We are developing a web-based app with lot of pl/sql procedures & functions (more than 150).
    But we have to suggest the number of cursors to be set in the INIT.ORA to the client.
    My question is "How to determine the number of cursors needed for my application to run smoothly for 100 users?".
    Appreciate your views.
    Thanks.

    The open cursors initialization parameter controls the number of cursors that can be open per session, so the number of simultaneous users is irrelevent. If you're watching the number of open cursors your sessions have open, you can set parameters based on the high-water mark you've seen in testing.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Determine number of channels on a DAQ card

    Is there a function to determine the number of channels on a given DAQ card?

    I found no native function to get this attribute; you can use DAQmxGetDeviceAttribute with DAQmx_Dev_AI_PhysicalChans attribute to get a list of available channels on a device and then parse the string counting channels. The following lines can be executed in the Interactive Execution window: provided the device name is correct they count how many input channels are present on the board:
    #include <ansi_c.h>
    #include <utility.h>
    #include <NIDAQmx.h>
    static int i;
    static char msg[512];
    static char *token;
    DAQmxGetDeviceAttribute ("Dev1", DAQmx_Dev_AI_PhysicalChans, msg, 512);
    i = 0; token = strtok (msg, ",");
    while (token) {
    i++;
    token = strtok (NULL, ",");
    DebugPrintf ("# of channels: %d\n", i);
     The same function has equivalent attributes for analog outputs, counters and digital I/O lines / ports.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Determine number of brushes with javascript

    I have the feeling it may have come up before (specifically in connection with rotating brushes), but I can’t locate it here or on PS-Scripts.com, so:
    How can one determine the number of Brushes in Photoshop?
    What I intend to use that information for is to save the last brush as a Set via JavaScript.
    Any help appreciated.

    Dang, once again I omitted to properly search xbytor’s code before posting.
    »PresetLister.js« appears to contain the necessary elements …
    Edit:
    In case anyone else ever needs it, I tried to extract the parts relevant to this specific task from xbytor’s Script:
    alert (loadBrushNames().length);
    ////// adapted from xbytor’s PresetLister.js //////
    function loadBrushNames () {
    cTID = function(s) { return app.charIDToTypeID(s); };
    sTID = function(s) { return app.stringIDToTypeID(s); };
    key = cTID('Brsh');
    var names = [];
    var classApplication = cTID('capp');
    var typeOrdinal = cTID('Ordn');
    var enumTarget = cTID('Trgt');
    var ref = new ActionReference();
    ref.putEnumerated(classApplication, typeOrdinal, enumTarget);
    var appDesc = app.executeActionGet(ref);
    var mgr = appDesc.getList(sTID('presetManager'));
    var max = mgr.count;
    for (var i = 0; i < max; i++) {
    var objType = mgr.getObjectType(i);
    if (objType == key) {
    break;
    if (i != max) {
    var preset = mgr.getObjectValue(i);
    var list = preset.getList(cTID('Nm  '));
    var max = list.count;
    for (var i = 0; i < max; i++) {
    var str = list.getString(i);
    names.push(str);
    return names;

  • Determine number of cached credential logins remaining?

    Is it possible to determine how many cached credential logons have been used? (or are remaining?)
    i.e. AD joined Windows 7 Pro laptop, configured for use whilst disconnected from the network.
    Cached logon information is controlled by the following key:
    HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\Current Version\Winlogon\
    ValueName: CachedLogonsCount
    Data Type: REG_SZ
    Values: 0 - 50
    So, this is set to the value we require. We want a way of determining how many remain...
    Quite happy to run a utility or script
    Grateful for any methods or suggestions
    Thanks
    David

    Hi,
    Like you post above, that registry can change the number of previous logon attempts that will cache.
    The valid  range of values for this parameter is 0 to 50. A value of 0 turns off logon caching and any value above 50 will only cache 50 logon attempts. By default, all versions of Windows remember 10 cached logons except Windows Server 2008.
    For more information, read this reference:
    Cached domain logon information
    http://support.microsoft.com/kb/172931
    Karen Hu
    TechNet Community Support

  • Determining number of files in export

    Hello
    Assume I want to take an export of one schema which is 250gb (select sum(bytes/1024/1024) from dba_segments where owner='...')
    I want to take export in 2gb chunks.
    How can I determine how many file to specify in "file" clause of the export command?
    My parfile will be like:
    filesize=2gb
    file=(prod_exp1.dmp, prod_exp2.dmp ,...... )         ??????

    On 10g and above, with export dump, you don't need anymore to know how many files you need.
    Use
    FILESIZE=2G
    DUMPFILE=mydumpfile%U.dmp
    %U will be replace by a number... as needed by the export process.
    Nicolas.

Maybe you are looking for

  • Edited tags of purchased songs/albums are not showing up on my iPhone 5s

    Greetings. I am quite anal about the way I tag my digital music library. After downloading a song from iTunes or ripping a CD, I use Mp3tag to edit the tags. I keep things extremely simple: title, artist, album, artwork, track number, genre, and some

  • How to print text in paper format iin smartforms

    Hi all,   I want a question that  how to print text in paper format like  paper divides into 2 parts and if the firstpart is full of text i.e., it exceeds the first page the text will be displyed in the second part of the first page. Usefull answers

  • Kernel panics after updating firmware

    Kernel panics began at startup after updating firmware about 2 weeks ago. Went through the KP repair routines prescribed by thexlab.com. Found no problems with the hard drive, permissions, etc. Did erase and install (with Leopard OS dvd bought from b

  • Can't select objects in my layout

    Using IDDCS2 on my iMac, I created a simple layout - saved in IDD and also saved as PDF. When I opened up the idd file again, I lost all 'boxes' so I can't select a box and I can't highlight or edit text. I've basically lost all functionality in the

  • "UnsatisfiedLinkError:  make_statement" when run in debugger

    I have a problem retrieving a ResultSet from a REF CURSOR -- apparently due to the JVM failing to locate requisite native code within Oracle. The problem is not in the code itself, but somewhere in the configuration / environment / debugger. I conclu