Writing a program

Hi,
Can someone please help me figure out how to create a program in java that adds up the squares and adds up the cubes of integers from 1 to N, where N is entered by the user?
I know the basics, I just don't know what to put in the loop body:
int startingvalue = 1;
int n = reader.readInt ("Enter the upper limit value:");
int sumofsquares;
int sumofcubes;
while (startingvalue <= n){
}

Math.pow (startingvalue, 2);
sumofsquares = startingvalue ++;
System.out.println (" The sum of squares is:");
reader.readInt (sumofsquares);
Math.pow (startingvalue, 3);
sumofcubes = startingvalue ++;
System.out.println (" The sum of cubes is:");
reader.readInt (sumofcubes);See how when you post code using the CODE button it is easier to read.
That looks right how you calculate the square but why do you add startingvalue to the sumofsquares variable instead? Also it would be a good idea to increment starting value at the end otherwise you will calulate the squares of 1,3,5,7 etc and the cubes of 2,4,6,8 etc.

Similar Messages

  • How to filter results of mara without writing abap program

    I  am running SE16 in SAP ECC searchig MARA table. I want to query such
    As ERSDA > u201801/03/2011u2019 OR LEADA > u201801/302/2011u2019, Through form interface, it seems
    I can only specify AND for two fields and not OR. Is there a way to specify the complex filter
    Without writing ABAP program.
    Thanks.

    Hello,
    For simple single table reporting as this just use transaction code SE16 or SE16N. Filter your results as you would in any standard report selection screen using the search bubble option on the selected fields. After inputting the table select "Settings --> Fields For Selection" at the selection screen from the toolbar to add fields for the search. You may then download the results from "System --> List --> Save --> Local File" (Spreadsheet).
    Regards,
    sifter

  • Need help for writing extract program

    hi
    i need help for writing extract program to retriew data from legacy system.
    i already developed bdc programs for me31k and me21.
    my requirement is to write extract program s for those t.codes.
    to retriew data from legacy system and stored in flat file.

    i need help with a java program. it is a program that allows the user to enter a student's GPA, number of extracurricular activities, and number of service activities. The user can not enter a gpa above 4.0 or below 0. The user can not enter a negative number for the number of both activities. If the student meets the following criteria: 1) GPA of 3.8 or above and at least one extracurricular activity and one service activity, 2) GPA below 3.8 but at least 3.4 and a total of at least three extracurricular and service activities, 3) GPA below 3.4 but at least 3.0 and at least two extracurricular activities and three service activities, the message "Scholarship candidate" should display. If the student does not meet the criteria above, then the message"not a candidate" should display. Can you help me, please?
    You haven't posted ANY 'java program' for us to help with.
    The forum is NOT a coding service. It is to help you with YOUR code.
    Post the code you have written and SHOW us (don't just tell us) how you compile it and execute it and the results you get. Then we can help you with any problems you are are having.
    If you need help understanding just what the program should be doing you need to ask your instructor to clarify the assignment.

  • Need help writing host program using LabView.

    Need help writing host program using LabView.
    Hello,
    I'm designing a HID device, and I want to write a host program using National Instrument's LabView. NI doesn't have any software support for USB, so I'm trying to write a few C dll files and link them to Call Library Functions. NI has some documentation on how to do this, but it's not exactly easy reading.
    I've written a few C console programs (running Win 2K) using the PC host software example for a HID device from John Hyde's book "USB by design", and they run ok. From Hyde's example program, I've written a few functions that use a few API functions each. This makes the main program more streamlined. The functions are; GetHIDPath, OpenHID, GetHIDInfo, Writ
    eHID, ReadHIC, and CloseHID. As I mentioned, my main program runs well with these functions.
    My strategy is to make dll files from these functions and load them into LabView Call Library Functions. However, I'm having a number of subtle problems in trying to do this. The big problem I'm having now are build errors when I try to build to a dll.
    I'm writing this post for a few reasons. First, I'm wondering if there are any LabView programmers who have already written USB HID host programs, and if they could give me some advice. Or, I would be grateful if a LabView or Visual C programmer could help me work out the programming problems that I'm having with my current program. If I get this LabView program working I would be happy to share it. I'm also wondering if there might already be any USB IHD LabView that I could download.
    Any help would be appreciated.
    Regards, George
    George Dorian
    Sutter Instruments
    51 Digital DR.
    Novato, CA 94949
    USA
    [email protected]
    m
    (415) 883-0128
    FAX (415) 883-0572

    George may not answer you.  He hasn't been online here for almost eight years.
    Jim
    You're entirely bonkers. But I'll tell you a secret. All the best people are. ~ Alice

  • Using JNI i am writing sample program i am getting the erro in jni.h

    Hi,
    i am writing sample programs using JNI interface while compliling the c program i am getting the error in jni.h file.
    wherever the JNICALL has in jni.h i am getting the error that particular line.
    can anyone help me on this regard?
    Thanks
    Balaji

    baalu999 wrote:
    Hi Thanks a lot for your update
    i found the correct Jni.h now i was able to compile my c program but i was unable to create .dll file in mainframe environment. can you please help me in this regard.No, because that makes no sense.
    A dll runs on windows. Nothing else.
    If you can't figure out how to create a dll then that is a windows question. And a windows forum works for that.

  • Problem in writing this program

    Please can anyone help me in writing this program, i am a student 
    Write a C++ program that reads a real variable x, integer variable N, and computes its exponential e<sup>x</sup> using the formula:
     Ex =  1 + x +
    x^2/2! + x^3/31 + x^4/4! + x^5/5 +...+ x^N/N!  (for N ≤ 10).
    Your program should define a function that computes factorial, which is called in the main function.
    Thanks

    Hi Kanayo
    The following program does
          total = x*0 +  x*1 + x*2 + x*3 + x*4 ...+x*N
    You may modify it for your formula. Use a recursive function or 'for' loop to compute a factorial.
    Regards
    Chong
    #include "stdafx.h"
    #include <iostream>
    using namespace std;
    int N;
    double x;
    float Fn( int n)
     double total=0.0;
     if (n<N)total= Fn(n+1);
     return(total+=x*n);
    int main()
     //double x;
     //int N;
     cout<<"Enter x: "; cin >>x;
     cout<<"Enter N: "; cin >>N;
     double total=Fn(0);
     cout<<total<<"\n";

  • What are the steps  involved in writing a program?

    hi experts ,
       I am writing reports? i want to know that what are the steps required to write a program?
    and also Explain different techniques to analysize a program?
    please send example programs with analysis?
    I definately award a good number of points to help full answers.

    hi sateesh,
        welcome to SDN.
    first of all check ur requirement.
    Analysis what r the events that are required in ur report.
    write a pseudo code for ur requirement
    and then write ur program.
    To analyse a program v have to use the these t/c :
    SE30 - Runtime Analysis.
    ST05 - SQL Trace.
    Regards...
    Arun.
    Reward points if useful.

  • Using SQ02 for writing ABAP programs

    Hello,
    I am using SQ02 coding section for writing some simple ABAP programs, mainly for reporting purposes. I would like introduce more power into my programs, but SQ02/SQ01 reports return "ACCESS_DENIED" when I for example try to call a function (GUI_DOWNLOAD).
    Can You advise how to extend SQ02 authorization to enable function calls?
    Maybe You know other place from which You can write programs without a developer key?
    Thanks,
    Pawel

    Hi Uday,
    do You mean that I have to first make a recording on cg3y using transaction shdb, then create a function module basing on this recording, and then use this function module in my code?
    Pawel

  • Need help writing small program!

    Hi. I'm learning Java programming, and I need help writing a small program. Please someone help me.
    Directions:
    Create a program called CerealCompare using an if-then-else structure that obtains the price and number of ounces in a box for two boxes of cereal. The program should then output which box costs less per ounce.

    class CerealCompare {
        public static void main(String[] args) {
            // your code goes here
    }Hope that helps.
    P.S. Java does not have an if-then-else statement.

  • I am writing a program that needs to draw gradient lines according to the points that i touch on ipad. For this i am using "DrawLinearGradient" function. But the 2 colors that i am giving for drawing gradient is not dividing equally in the complete line.

    Can anyone please help about the parameters that need to be passed corectly.
    CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
    CGColor[] colors = {UIColor.Red.CGColor,UIColor.Green.CGColor};
    float[] locations = {0.0f,0.5f,0.5f,1.0f};
    CGGradient gradient = new CGGradient(colorSpace,colors,locations);
    ColorMessage.FontSize = width;
    context.SetLineWidth(width);
    context.SaveState();
    context.Clip();
    context.DrawLinearGradient(gradient,penVertices[0],penVertices[count-1],0);
    context.StrokePath();
    gradient.Dispose();
    colorSpace.Dispose();
    context.RestoreState();

    Wouldn't this be better posted in a developers forum? This forum is for Using an iPad, not writing programs for one.

  • Hand writing pad program

    Hope this is the right area to talk about this.
    I have a Touchsmart tm2 p/n xq322aar
    HP support is being a joke again always telling me to wipe my HDDD clean and is making it hard for me, the annoying trouble I am running into is when I write into the writing pad, it alot of time auto correct  me when I truly dont want it to. when I write MB it auto correct and when i fix it ...it will fight me and try to choose a word. When I finaly get it to stay at MB and continue on it decided to combind my other letters and changed my MB.... here what I am trying to write one out of the 100s of words I am trying to write... 128MB x1600. is there away to disable the auto correct or another program I can use so I can write things down vs trying to type...
    THank you for your time.
    Ps incase it should be check on. I cant switch my graphic sometimes and I whould have to restart the comp and it will work untill it finaly stop allowing me to switch. but it a secoundary thing I can deal with TY

    Sorry for the late reply. Only this laptop can get in this forums for some odd reasons.
    Now I am not refering to word pad note pad microsoft words and so on I am refering to the lil box that is cosinder a writing area where you can write your letters and then press the insert button to insert it into said programs like Words. Words and word pad are not quto correcting causes they been long disable. it the lil yellowish area I will tkae a screen shot now it will be in my photobucket.
    http://i16.photobucket.com/albums/b48/HardMan-EAA-​/writingpad.jpg
    there it is...so the problem is it assume I am misspelling and try to correct me I do understand it just try to reconize my hand writing but I know the diffrent from auto correcting and reconitions. this word wont be in the data base causes it wont be ( x1600 128mb) that a type of video card  I can easly write all the numbers and the letters no problem but when it think I made a mistake it changed what I write ...if it still a lil hard to understand what I am saying I can see if I can record what I am trying to say.
    I cant find anythign related to disabling auto correcting let alone to tell the program that the recent word was incorrctly auto corrected and I have a choice to send it to microsoft but I cant tell it what the correct word is.
    Dose HP have it own program or is there another one I can use that will have more options to adjust ? or to disable this bloody auto correct crap...never liked it on any device ... Oh I take alot of short cuts as well Cant (cnt) my name R2, and so on that another reason why I dont want that autoorrect...well hope I make sense.. thank you for you

  • Need Help in Writing a program using a two-dimensional Array

    I need to write a program that takes 16 integers as inputs and determine whether the square is a magic square(sum of each row, column, and diagonal is the same constant) and display the result in a message Box. Please Help!!!!!

    stick the 16 ints in an int[4][4] and then just write the methods. i guess thats the hard part though. the most cumbersome and longest possible way to do it is just write everything out. ie if(int[1][1] + int[2][1] + int[3][1] etc...). a better way would be to use a bunch or for loops, but you'll have to figure that out yourself.

  • How can I add a new domain to portal by writing a program

    I have been studied portal for a while but I still dont know how to solve this problem. Actually, I need to provide an api for my partner's program which is running on the iplanet application server. Therefore I tried to write a servlet which would invoke the AddComponent class which is the core part of ipsadmin tool. If I write a standalone java application, it works fine but once I changed it to servlet and deployed to portal server it could not work properly.
    Then, I tried to use Java JNI to add a domain to directory server directly but I can not find the webtopdomain this object in the schema. Therefore the second approache failed either. Please could any of you can help me or give me some insight? Thank you very much

    Finally, I find a way to solve this problem although I still can not make it work by using a servlet to invoke ipsadmin or AddComponent class. The easiest way to solve this question is to access Ldap directly. I used ipsadmin to add a new domain and role first and then checked all their attributes in the Ldap. I wrote a program to insert the domain and role entry with the same attributes as using ipsadmin and it works just fine. I really can just add domain and role entry even though there are no webtopdomain and webtoprole objectclasee in the schema.

  • Help writing a program that uses Add/Remove programs

    Hey everyone,
    I'm trying to create a program that will utilize add/remove programs to repair an installation of a program. Specifically I'm trying to write something that will help automate repairs of QuickBooks installations. I've tried using Filemon to figure out what executables I might need to call and I've searched high and low in the forums and Google for help but I'm not getting anywhere. Is there some sample code out there that shows you how to work with the Add/remove programs screen and the programs in it?
    Thank you for any help you all can provide me.

    [email protected] wrote:
    It might be possible if you use the JNI, ** ouch ** That's going to hurt.
    but more than likely, Java is a poor choice for the program that you're trying to write.I'll second that. You might want to try C# if you want to write a more Windows-centric program. Its syntax is extremely similar to Java's (I wouldn't say that it was ripped-off of Java, but you could say that probably and not be wrong). But it is a powerful language with a rich library and would interact with the Windows libraries much more readily than java would.

  • Writing custom program errors to SLOG

    I am looking for a way to put errors from custom program ( which would run as job) to system log, which should be visible via SM21. Can any of you help me with a function module with which I can achieve it ?

    Hi Indrade,
    Is it your first post in SDN ? Welcome!
    for your problem try the following procedure:
    1. Refresh memory
      CALL FUNCTION 'BAL_GLB_MEMORY_REFRESH'
        EXPORTING
    *   I_AUTHORIZATION                =
          i_refresh_all                  = 'X'
    *   I_T_LOGS_TO_BE_REFRESHED       =
        EXCEPTIONS
          not_authorized                 = 1
          OTHERS                         = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    2. Create a Log
    * define some header data of this log
      l_s_log-extnumber    = pu_ext_number.
      l_s_log-aluser       = sy-uname.
      l_s_log-alprog       = sy-repid.
      l_s_log-object       = pu_object.
      l_s_log-subobject    = pu_subobject.
    * create a log
      CALL FUNCTION 'BAL_LOG_CREATE'
           EXPORTING
                i_s_log                 = l_s_log
           IMPORTING
                e_log_handle            = pc_log_handle
           EXCEPTIONS
                log_header_inconsistent = 1
                OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    3. Add a message to the Log
      DATA:
        l_s_msg      TYPE bal_s_msg,
        l_log_handle TYPE balloghndl.
    * define data of message for Application Log
      l_s_msg-msgty         = pu_msgty.
      l_s_msg-msgid         = pu_msgid.
      l_s_msg-msgno         = pu_msgno.
      l_s_msg-msgv1         = pu_msgv1.
      l_s_msg-msgv2         = pu_msgv2.
      l_s_msg-msgv3         = pu_msgv3.
      l_s_msg-msgv4         = pu_msgv4.
      l_s_msg-probclass     = pu_probclass.
      l_s_msg-context-value = pu_context.
      GET TIME STAMP FIELD l_s_msg-time_stmp.
    * add this message to log file
    * (I_LOG_HANDLE is not specified, we want to add to the default log.
    *  If it does not exist we do not care =>EXCEPTIONS log_not_found = 0)
      CALL FUNCTION 'BAL_LOG_MSG_ADD'
           EXPORTING
                i_log_handle  = l_log_handle
                i_s_msg       = l_s_msg
           EXCEPTIONS
                log_not_found = 0
                OTHERS        = 1.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    4. Save Log
      CALL FUNCTION 'BAL_DB_SAVE'
           EXPORTING
                i_t_log_handle   = p_t_log_handle
           EXCEPTIONS
                log_not_found    = 1
                save_not_allowed = 2
                numbering_error  = 3
                OTHERS           = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    I hope it will helps.
    Please remember to reward points if the answer is useful, and to close the post when your problem is solved
    Regards, Manuel

  • Need help writing Labview Program!!!!!

    I have a labview project that needs to be finished. I was not the original creator of the program and the guy who created no longer is involved with the project and I am left to finish it. Could you make the final adjustment so I can turn this into my professor and get the final grade. Thanks! Willing to pay! Negeotiable price!!!!!!!!

    Need help completing assignment! Could anyone assist me in this project!
    Attachments:
    dial tone detection.zip ‏1253 KB

Maybe you are looking for