How to add results from a method

Hi-
I have written the following code that takes an input integer, and figures out every odd integer contained inside such as inputting 7 would give you 5,3,1. How can I modify this code to take those answers in my example and get it to add them to equal 9 in this case? I have tried making my method return an int, but I am doing something wrong, and have banged on this for hours, resulting in a giggling compiler. Even if I get some help on the return, I am baffled by how to get another method(?) or whatever to "remember" the parsed out odd integers
and then add them.
Thanks
Brad
public class OddSum
public static void main (String [] args)
System.out.println ("Please Enter An Integer.");
int varOne;
EasyIn easy = new EasyIn();
varOne = easy.readInt();
System.out.println("You Entered: " + varOne);
figureOdds(varOne);
public static void figureOdds (int varOne)
int num;
for (num = varOne-1; num >0; --num)
int monkees;
monkees = num;
if(monkees%2 != 0)
System.out.println("The Odds Contained in your Input Integer are: " + monkees);
}

Hmmm-
neither of those solutioins are working correctly. Say for example I entered a 5. First (and what I had working)
I wanted to find all the odd ints contained in 5 not including 5: 3 and 1. THEN I wanted to add them for a result of 4. It was helpful to see that I could declare a var named sum and set it to 0 as in this:
int sumOfOdds = 0;
for (num = varOne-1; num >0; --num)
//int monkees;
//monkees = num;
if(num%2 != 0)
sumOfOdds += num;
System.out.println("The Odds Contained in your Input Integer are: " + num);
but when you compile and enter "11" as the int it comes up with 55 instead of 25 as it should.
In the second reply with code:
public static int figureOdds(int varOne) {
int num, sum = 0;
for (num = varOne-1; num > 0; --num) {
if(num%2 != 0){
sum += num;
System.out.println("The Odds Contained in your Input Integer are: " + num);
return sum;
it gives me the same result as I was getting. Am I missing something that was unsaid, but supposed to be understood?
Thanks
Brad

Similar Messages

  • How to compare result from sql query with data writen in html input tag?

    how to compare result
    from sql query with data
    writen in html input tag?
    I need to compare
    user and password in html form
    with all user and password in database
    how to do this?
    or put the resulr from sql query
    in array
    please help me?

    Hi dejani
    first get the user name and password enter by the user
    using
    String sUsername=request.getParameter("name of the textfield");
    String sPassword=request.getParameter("name of the textfield");
    after executeQuery() statement
    int exist=0;
    while(rs.next())
    String sUserId= rs.getString("username");
    String sPass_wd= rs.getString("password");
    if(sUserId.equals(sUsername) && sPass_wd.equals(sPassword))
    exist=1;
    if(exist==1)
    out.println("user exist");
    else
    out.println("not exist");

  • How to filter results from 4 dynamic list menus depandant on how many of them are selected

    I have a search page with a form with 4 list menus and 1 submit that post the results to the results page. I can create a record set that either retrieves the correct data from my database if a selection is made from all four menus Or i can create the recordset if only 3 menus have a selection or the same for 2 menus and 1 menu. However i want the user to be able to make a selection from either 1, 2, 3 or all 4 of the menus and the exact data be retrieved. At present if i try to combine the recordset using AND and ORs the results are not specific enough, for example the 4 menus are Location, Type, Price & Style if a user selects from all 4 i only want to retrieve data that matches all 4 criteria, but at the same time if the user selects only 2 of the menus the i want it to retrieve data that matches specifically those 2 variables. I´m not actually sure if i should be creating a more advanced sql query of if its the php side of things that i need to look at. This is my first dynamic site so please be aware i´m still a learner where php and sql is concerned. Please can anyone help?  

    Hey there,
    Thanks for replying,
    I too am using Dreamweaver recordset, my local server is XAMPP ( apache php mysql), i´have pasted my sql recordset below to give an idea of what i´m trying to do, however this does not work as i´m trying to select the exact data based on 4 menus PRICE TYPE LOCATION and BEDS, and also want the search to work if the user only selects options from either 1, 2, 3 or 4 of the menus, with the code as it is if the user select only two options from 2 of the menus the results don´t just find (for example) all results for location AND price they find all results for the location varibale OR the price variable rather than a match for both, if you see what i mean?
    Any suggestions?  
    SELECT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number`
    FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid
    WHERE (location=varloc AND price = varprice AND type=vartype AND beds=varbed ) OR (price=varprice AND location=varloc AND type=vartype) OR  (price=varprice AND location=varloc AND beds=varbed) OR (price=varprice AND beds=varbed AND type=vartype) OR  ( location=varloc AND type=vartype AND beds=varbed) OR  (price=varprice AND location=varloc) OR (price=varprice AND type=vartype) OR (price=varprice AND beds=varbed) OR (type=vartype AND location=varloc) OR (type=vartype AND beds=beds) OR (location=varloc AND beds=varbed) OR (price = varprice OR beds=varbed OR type=vartype OR location=varloc)
    ORDER BY detailstable.trueprice ASC
    Look forward to receiving your thoughts,
    Linda
    Date: Wed, 21 Oct 2009 14:36:33 -0600
    From: [email protected]
    To: [email protected]
    Subject: how to filter results from 4 dynamic list menus depandant on how many of them are selected
    Hiya,
    I'm just doing my first dynamic site too, and am at a similar level to yourself.
    Can you give us more info re the site. What software, eg Dreamweaver etc are you using, and is your server using PHP or ASP etc?
    For what I've used, I amended the SQL side of things in the recordset in Dreamweaver. That way, you can test the SQL as you're setting up the recordset.
    Let me know how you're going on anyway
    Cheers
    Andy
    >

  • YouTube - How to add videos from youtube on jsf-adf

    YouTube - How to add videos from youtube on jsf-adf.
    when i using iframe i can't send data from beans.

    you can use a <f:verbatim> tag in your page and in it just write the HTML code for embedding a video.
    and can i send data from beans class in html components?
    i wrote this
    <af:iterator id="i2" var="row"
    value="#{MyBean.src_items}"
    varStatus="st">
    <af:showDetail disclosed="false" id="sd1"
    styleClass="AFStretchWidth"
    disclosedText="#{row}">
    <f:verbatim>
    <iframe id="ifv" src="#{row}"/>
    </f:verbatim>
    </af:showDetail>
    </af:iterator>
    but that were not worked .
    Edited by: Vakhushti on May 9, 2011 12:40 PM

  • How to add results of Loop into a Cursor

    Hi,
    I am opening a cursor and looping through each row (it has a select query that queries based on the value of a column obtained from another cursor).
    How can I add all the rows to a new cursor (along with the column value I am getting from the first cursor), as I want to return that to a java program.
    Can I create a new cursor and add the final data to it (that contains all rows), if yes How do I do that?
    Thanks,
    Rommel.
    Message was edited by:
    rommelsharma

    Trying to add data from one cursor to another cursor shows a basic misconception on your part of what a cursor is.
    First, what a cursor is not - it is not a result set. An in-memory set of rowids or results for a SQL. With 1000's of cursors on a database, how would this scale when every cursor needs space for storing its results?
    A cursor is a SQL program - a set of instructions (as per the SQL's execution plan) of how to get the results for that SQL. When a cursor fetch is performed, this program returns the next set of rows from the actual database tables.
    So you cannot take data from one or more cursors and then wrap that into a 3rd cursor.. or more accurately, you should not. The fact that it can be hacked in PL/SQL simply says a lot of the flexibility of PL/SQL.. and not about good sensible use.
    So how then do you "add cursors" together? You do it at SQL level. A cursor is a program. So instead of creating multiple programs, each returning its own results, you make it a single program.
    You combine the SQLs. This means using UNION, JOIN, INTERSECT, etc.
    Solve the problem in SQL first and foremost. That is the most powerful language to use to crunch database data. Do not make the major and fatal performance mistake of treating SQL as a simplistic I/O library for merely reading and writing records.

  • How to add users from person or group field in a sharepoint list to sharepoint group

    Hi,
    How to add users(single or multiple) from person or group field in a sharepoint list to sharepoint group programmatically?
    Any suggestions would be appreciated.
    Thank you,
    AA.

    Hello,
    Use SPGroup.AddUser() method to add user in group. I have just written sample code in notepad so it is not tested:
    SPSecurity.RunWithElevatedPrivileges(delegate()
    using(SPSite Site = new SPSite(SPContext.Current.Site.Url))
    Using(SPWeb Web = Site.OpenWeb())
    SPList list = web.Lists["ListName"];
    SPQuery query=new SPQuery ();
    query.Query = "<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>Test</Value></Eq></Where>";
    SPListItemCollection items = list.GetItems(query);
    if(items.Count > 0)
    foreach(SPListItem item in items)
    //Get USers from person or group column
    SPFieldUser userField = (SPFieldUser)item.Fields.GetField("Users");
    SPFieldUserValueCollection userFieldValueCollection = (SPFieldUserValueCollection)userField.GetFieldValue(item["Users"].ToString());
    SPGroup spGroup = spSite.RootWeb.Groups[groupName];//group name
    if (users.Count != 0)
    bool isUserInGroup = false;
    foreach (SPFieldUserValue user in users)
    foreach (SPUser item in spGroup.Users)
    string itemUserName = item.LoginName;
    string UserName = user.User.LoginName;
    if (itemUserName == UserName)
    isUserInGroup = true;
    break;
    if (!isUserInGroup)
    spGroup.AddUser(user.User);
    The above code will query list item and then get users from "Users" column. Now it will check whetehr user is already in group not, if not then add user in group.
    http://rajanijilla.blogspot.sg/2012/09/add-users-to-group-programmatically.html
    Hope it could help
    Hemendra:Yesterday is just a memory,Tomorrow we may never see
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

  • How to use Results from Another Query for SAP BW universes

    Hi Everyone,
    I have two SAP BI universes.In my First universe I have Sales Doc no (dimension) and Orderqty (Measure) and in my second universe I have Sales Doc no(Dimension) and BillQty (Measure).
    Here in my first dataprovider I have 1200 rows of data and in second dataprovider I have 75,000 rows. The report should fetch only the BillQty details that matches to corresponding  Sales doc no in first data provider.
    I want to place all these fileds into a single report like as shown.
    (Datarpovider1)                (Datarpovider1)                    (Datarpovider2)
    *Sales Doc No*               Orderqty                           BillQty
    Here I am able to generate single report using merge dimension but it is leading to performance issues. I want to restrict the values at query level by passing the First dataprovider Sales doc no to second Data provider Sales doc number using Results from Anothery Query feature so that It can fetch only the matching records.
    I tried it but it was giving the follwing error:
    A filter contains a wrong value. You cannot run this query. (Error: WIS 00007)
    How Can I get rid of this error. Can we use Results from Anothery Query option for OLAP universe. Are there any limitation on it.
    All this I am doing in Webi Rich Client.
    Appreciate your help
    Thanks &in Advance
    Kiran Saka

    Hi Kiran,
    I think the filter has a wrong operand. For example, a filter with an empty constant, or a filter that deals with numeric values is defined with an alphanumeric value.Check out for this.
    Regards,
    Neeraj

  • HT1473 How to add music from macbook pro to iPad

    How do I add musci from Macbok pro to ipad2?

    Open itunes, connect ipad, select what you want, sync.

  • How to add name from text file to jtable?

    hello all,
    how to add name (string) from the notepad file(.txt) into jTable rows.
    I am not able to add it.
    try {
                 FileInputStream fis = new FileInputStream("Devices/Devices_Lst.txt");
                 BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                 String line = null;
                 Vector data = new Vector();
                 line = br.readLine();
                 while ( (line = br.readLine()) != null)
                    int rowCount1 = nmsTable.getRowCount();
                    for(int i=0;i<rowCount1;i++)      
                        myTableInit();  // it initialize the table
                       /* nmsTable.setValueAt(i+1,i,0);
                        Table.setValueAt(line,i,1);
                        Table.setValueAt(" ",i,2);
                        Table.setValueAt(" ",i,3);
                        Table.setValueAt(" ",i,4);
                        Table.setValueAt(" ",i,5); */
                        int rowNo = nmsTable.getRowCount();
                        row.addElement((rowNo+1));
                           //row.addElement(ipText.getText()+"-"+nameText.getText());
                           row.addElement(line);   
                           row.addElement((String)" ");
                           row.addElement((String) "");
                           row.addElement((String) "");
                           row.addElement((String) "");      
                            row.addElement((String) "");      
                            rows.add(row);                                     //rows is the Vector for table row.
                            Table.addNotify(); 
                  br.close();
                 if possible give me some examples.
    thank you.

    For every row you need to create a new Vector and add the data to that Vector. Then the Vector is added to the TableModel.
    If you add 6 items to the single Vector, then you will get 6 columns. So you need to create 6 Vectors and add a single item to each Vector and therefore you will end up with 6 rows with 1 column of data.

  • How to get result from another JSP file?

    I have to write a jsp (my.jsp) to get information from another jsp file (other.jsp).
    The other.jsp return integer value (0 / 1) so that user can tell if certain service is available or not. And in my.jsp I need to collect such result and other information from a text file to make up of a XML string.
    How can I call other.jsp to get the result? Thanks a lot.

    Hi, I think I didn't describe the problem clearly
    enough. In fact, there is a JSP file, and if our
    database is currently connected, the JSP will return
    value 1, otherwise, it will return 0. My java program
    need to get that result, and then form an XML string,
    and send the string back to the client. I'm just
    wonder how can I write such a program to read result
    from JSP file. Thanks a lot.Why is this function implemented as a JSP file? It should be implemented as a bean. It would be simple to get the information you require from that bean.

  • How to add photo from Photos app as iCloud/user avatar?

    Hello,
    I would like to change my login and iCloud user avatar. I have photos in the new Photos app, but I can't import or drag&drop files on the settings screen from Photos.
    "Take a photo with your iOS device or manually add photos from the Photos app." - I would like to do that, but how?
    Thank you!

    Hello,
    I would like to change my login and iCloud user avatar. I have photos in the new Photos app, but I can't import or drag&drop files on the settings screen from Photos.
    "Take a photo with your iOS device or manually add photos from the Photos app." - I would like to do that, but how?
    Thank you!

  • How to add music from ipod to brand new laptop

    I just bought a new laptop and now downloaded itunes, i was needing to know how to add my music from my ipod touch to my itunes library?

    - Transfer iTunes purchases by:
    iTunes Store: Transferring purchases from your iPhone, iPad, or iPod to a computer
    - Transfer othr stuff with third-party programs discussed here:
    Best iPod to PC

  • How to add music from a second computer to my iPhone 5

    I just got an iPhone 5. I can manually control music from my personal laptop and put it on my iPhone. However I can't add it from my brother's lap top. When ever I try to click "manually manage" on his computer, it tells me to erase everything from my iPhone and sync his library. I did autherize  hi computer. How do I add music from his computer with still keeping all of my current music?

    Thanks AmishCake.
    While I'd prefer to not have to do this I suppose it's the only way with my current set up.
    Lots of hostile attention on this forum from people who claim to not care about what I do.

  • How to present results from a sql-query in java

    Hi - I'm having problems finding out how to present data from a database-query in a nice looking way in a JFrame. Want to present them similar to the way they are presented in the database. Is there an easy way doing this?

    Tried to use a JTable, but it's difficult when data in the table should be able to change all the time, i.e the number of rows. What is a Html-table? Can i use it in an application?

  • How to add folder from KM content to Portal Favorites for selected users

    Hi all,
    I have cretaed  a folder in KM content (In documents) for uploading implementation related ddocuments.
    how to add this folder in "Portal Favorites" of selected users only.
    Please guide.
    Thanks in advance.

    Hi,
    well one way could be the following.
    Go into KM-Content --> Repository "userhome" --> select the user you want --> navigate into his folder Favorites --> create a new internal link in this folder to the folder you want
    In the favorites of the user there is now a link to the desired folder and after clicking a new window will be opened. You can copy this internal link to the favorites folder of the other users you want.
    Regards
    Alex
    Edited by: Alexander Götz on Apr 16, 2009 5:12 PM

Maybe you are looking for