Pseudocode

for i : = 1 to 20 do
for j := 1 to i do
for k := i to j do
for m := 1 to k do
print (i * j)
I am not interested in an answer; I am able to type in to Java and see what the answer is. I want some ideas in relation to the approach in solving this problem in an examination.

chetah wrote:
You are missin the point. The answer is not the issue. I indicated that I was able to get the answer. What I was looking for is a possible algorithm or formula that can be used to solve the question quickly.Oh, there is a very easy algorithm to calculate it by hand. I just don't feel like posting it here. Why? Because you have the nasty habit to never thank someone who takes the time answering you.

Similar Messages

  • Java code to pseudocode

    Hi, i have written this program but I also need to submit the pseudo code for it and i'm not really sure how to do this.
    Here is a sample of the code I have written, if someone could please get me on the write track so i can write the pseudocode for the whole thing that would be great.
    Java code;
    import TerminalIO.*;
    public class MyFutureTIO
    KeyboardReader reader = new KeyboardReader();
    ScreenWriter writer = new ScreenWriter();
    public void run()
    // global instance variables
    char keepdepositing='N';
    double deposit, rate, balance=0 , withdrawals=0, interest=0, withdrawalyears=0, finalbalance=0, counter=0;
    int age, years=0, continuedyears=0;
    // Initial inputs to be able to determine when the loan matures
    writer.print("Amount deposited per month: ");
    deposit = reader.readDouble();
    writer.print("Your age: ");
    age = reader.readInt();
    writer.print("Interest rate: ");
    rate = reader.readDouble();
    deposit = deposit*12;     // This is the yearly deposit amount
    rate = rate/100;          // To convert the rate to a decimal
    if (age >=60){      // This if statement is used when the age is over 60 years
    years = 0;
    for (int i = 0; i < years; i++)
    balance = (balance + deposit) * (1 + rate);
    if (counter % 10==0)
    rate = rate + 0.01;
    counter++;
    writer.print("As you are 60 or older, your account is at maturity\n");
    writer.print("Your account has a $" + balance +", but you can choose to deposit money from this point onwards\n");
    writer.print("Would you like to start depositing?\n");
    keepdepositing = reader.readChar();          
    if (keepdepositing == 'N'){  //the user doesn't want to open an account
    writer.print("As you don't want to start depositing and your account has a $0 balance no account has been opened\n");
    else if (keepdepositing == 'Y'){   //the user wants to start depositing into the account
    writer.print("How many years would you like to deposit for? ");
    continuedyears = reader.readInt();
    for (int i = 0; i < continuedyears; i++)
    balance = (balance + deposit) * (1 + rate);
    writer.print("Your balance at this time will be: $" + balance);
    interest = (balance*rate)/12;
    writer.print("Your account will earn $" + interest + " per month in interest after this point\n");
    writer.print("How much would you like to withdraw per month? ");
    withdrawals = reader.readDouble();
    writer.print("How many years would you like to withdraw for? ");
    withdrawalyears = reader.readDouble();
    for (int i = 0; i < withdrawalyears; i++) // do i need the counter here?
    finalbalance = (balance - withdrawals*12)*(1 + rate);
    writer.print("After this time your account will have a balance of: $" + finalbalance + "\n");
    }

    Yeah i did write this program, and i have actaully started to write the pseudocode but it doesn't seem write, i'm not sure if i'm putting to much in or not enough.
    All of my notes say not to use any java key words in pseudocode, and this is confusing me a bit.
    This is what I started to write for the psuedocode;
    Get deposit
    Get age
    Get rate
    If (age >= 60
    years = 0
    for (int 1=0;
    Balance = (balance + deposit)*(1+rate)
    Print As you are 60 or older, your account has reached maturity
    Print Your account has a $0 balance, but you can choose to deposit money from this point onwards
    Print Would you like to start depositing?
    if (keepdepositing == �N�)
    Print As you don�t want to start depositing and your account has a $0 balance no account has been opened�
    else if (keepdepositing == �Y�)
         Print How many years would you like to deposit for?
         Balance = (balance + deposit) * (1 + rate)
         Print Your balance at this time will be $balance
         interest = (balance*rate)/12
         Print Your account will earn $interest per month after this point
         Print How much would you like to withdraw per month?
         Print How many years would you like to withdraw for?
         final balance = (balance � withdrawals*12)*(1 + rate)
         Print After this time your account will have a balance of $finalbalance

  • What is the standards to write pseudocode

    Hi all,
    If any one knows about standards of Pseudocode
    plz pass it to me.
    I need to write some pseudocode with proper standards.
    Thanks.

    There isn't really a "standard" for pseudocode per se. Pseudocode is just a term that describes something that's between natural language and programming source code. It tends to be somewhat like one or more actual programming languages, but without worrying about precise details of syntax, semicolons, etc., and there will be natural language thrown in for things that are tedious to write in a more computer-ish style.
    For example:
    fetch all students and their courses from database where student's registration status is complete
    for each combination of student and class
      if student has not completed prerequisites for class, email notice to student that he must get instructor's written permission.

  • Confusing with these pseudocode

    I never write the psedocode for instantiable classes, so I am pretty confused at this time. For example, the following codes, how to convert them to pseudocode?
    public class Invoice
         private String numb;
         private String descr;
         private int qu;
         private double pr;
         public Invoice()
              numb="";
              descr="";
              qu=0;
              pr=0;
        public void setPartNumber(String numb)
          this.numb=numb;
        public String getPartNumber()
            return numb;
        public void setDescription(String descr)
          this.descr=descr;
        public String getDescription()
            return descr;
        public void setQuantity(int qu)
            this.qu=qu;
        public int getQuantity()
            return qu;
        public void setPrice(double pr)
            this.pr=pr;
        public double getPrice()
            return pr;
        public double getInvoiceAmount()
            return qu*pr;
    }Thanks

    Check out the wikipedia definition of pseudocode:
    Pseudocode (derived from pseudo and code) is a
    compact and informal high-level description of a
    computer programming algorithm that uses the
    structural conventions of programming languages, but
    omits detailed subroutines, variable declarations or
    language-specific syntax.
    I put in bold the key phrase to me. It is useful in
    simplifying the description of programming
    algorithms. Your code above algorithm-deficient.
    It's not bad code, and it's not wrong code. It is
    just not a good example of what pseudocode is useful
    for.I have gone through with this and now understand when I have to use pseudocode.
    thx:)

  • Help with pseudocode

    hi. can someone helpe me translate this pseudocode please:
    for each vertex v
            set kv to false
            set pv to unknown (or none, if v is the start vertex)
            set dv to infinity (or 0, if v is the start vertex)
        PriorityQueue pq = new PriorityQueue()
        pq.enqueue(start vertex, 0)
        while (!pq.isEmpty())
            vertex v = pq.dequeueMin();
            if (kv is false)
                kv = true
                for each vertex w such that edge v -> w exists
                    if (dw > dv + C(v, w))
                        dw = dv + C(v, w)
                        pw = v
                        pq.enqueue(w, dw)
        }

    Care to tell me what's wrong with this.
    I was showing him what a for loop looks like and what
    a for each looks like.Norweed,
    Your code snippet is liable to cause far more confusion than clarity, for the following reasons:
    The OP's pseudocode references "v" as an individual vector; your suggested code uses "v" as the collection of vectors.
    The OP makes no mention of his collection of vectors being stored in an ArrayList; your code could be interpretted as "one must use an ArrayList in order to do a for loop".
    Your ArrayList is not initialized, yet you make no "do initialization stuff" indication between its declaration and usage.
    ArrayList does not have a component "size".
    The usage of an index, "i", is extraneous as the pseudocode has no requirements for tracking a numeric index as the code loops through the collection of vectors. I find your later comment "I was showing him what a ... for each looks like." puzzling. Indeed, a for each style loop would have been appropriate, but it is missing from your post.
    In short, to someone who has expressed confusion over how to wrie a for-loop, I cannot fathom how the following four lines of text would do anything but confuse that person even further:
    ArrayList v;
    for(int i=0; i<v.size; i++){
    do stuff;
    }>
    Message was edited by:
    kevkirk

  • Chessmate pseudocode

    me and a couple friends are making a chess game.. but we cant figure out how to code the chessmate method (it checks to see if the game is in chessmate)
    could anyone offer pseudocode?

    if king is in check; and
    checking piece(s) cannot be captured; and
    no piece can be interposed; and
    there are no valid escape squares...remembering the special rule that castling is not
    legal when the king is in check...unless the Goodyear blimp is flying by
    >
    checkmate!

  • Translating pseudocode??

    "left" is an int parameter in my method...
    "k" is an int representing the middle index of an array called "a"...
    Here is the pseudocode....
    if searchValue < a[k]
    return the result of searching the array from left to k - 1
    if searchValue > a[k]
    return the result of searching the array from k + 1 to right
    Thanks for any help!!!!

    Ok here we go
    if searchValue < a[k]
    return the result of searching the array from left to k - 1
    if searchValue > a[k]
    return the result of searching the array from k + 1 to rightpublic int[] searchFunction(int left) {
    //Assuming searchvalue a global parameter...
    //Assuming array also global..
    int k = a.length/2;
    int left = 3 //HardCoded.
    int right = 7; // this i have assumed a variable cos left has also been assumed as an variable
    int start = 0;
    int stop = 0;
    int len=0;
    if (searchValue < a[k]) {
    if (left < k) {
    len = k - left;
    start = left;
    stop = k;
    } else if (searchValue > a[k]) {
    len = right - k;
    start = k+1;
    stop = right;
    String str = new String[len]; //Assuming a as an String array.
    for (int i=start; i<stop; i++) {
    str[i] = a;
    return str;
    I don't know that this will work or not.. It might have some errors also but atleast try it out.. i have not compiled it .. may i'll be able to solve the problem.

  • From pseudocode too regular code

    My brain has blocked totally....
    Hat do I make a regular java code of this pseudocode:
    for <each Vertex w adjacent to v>
    or this, They are the same
    for <each nabour w to v>

    class Control{
        Helper helpMe = new Helper();
        In file;
        int maxnr;
        int p = 1;
        int dist;
        static int infinity = 1000000000;
        Activity pred;
        public HashMap<String, String> tmpReg = new HashMap<String, String>();
        public PriorityQueue <Activity> prQue = new PriorityQueue<Activity>();
        Activity[] actRegister;
        String[] test;
        public Control(String fname){
            file = new In(fname);
            maxnr = file.inInt();
            actRegister = new Activity[maxnr + 1];
            test = new String[maxnr + 10];
            dist = infinity;
        void readFile(){
            //System.out.println("kommet hit");
            file.inLine();
            Activity act;
            int pos = 1;
            while(!file.endOfFile()){
                String line = file.inLine();
                System.out.println(line);
                split(line);
        void split(String line){
            StringTokenizer word = new StringTokenizer(line);
            String tmpNr = word.nextToken();
            String name = word.nextToken();
            String tmpTime = word.nextToken();
            String antPers = word.nextToken();
            int nr = helpMe.stringArrayToInt(tmpNr);
            int time = helpMe.stringArrayToInt(tmpTime);
            int manpower = helpMe.stringArrayToInt(antPers);
            int cntPred = 0;
            String test = "";
            while(word.hasMoreTokens()){
                String pred = word.nextToken();
                test += pred + " ";
                cntPred++;
            tmpReg.put(tmpNr, test);
            createAct(nr, name, time, manpower, cntPred-1);
        void createAct(int nr, String name, int time, int pers, int cntPred){
            Activity act = new Activity(nr);
            act.name = name;
            act.time = time;
            act.staff = pers;
            act.cntPredecessors = cntPred;
            actRegister[nr] = act;
        void edgeStart(){
            int actRegLength = actRegister.length;
            for(int i = 1; i < actRegLength; i++){
                String x = tmpReg.get("" + i);
                createEdgeList(i, x);
        void createEdgeList(int edgeNr, String pred){
            StringTokenizer splitPred = new StringTokenizer(pred);
            while(splitPred.hasMoreTokens()){
                String s = splitPred.nextToken();
                int fromEdge = helpMe.stringArrayToInt(s);
                if(fromEdge != 0){
                    addNext(actRegister[fromEdge], actRegister[edgeNr]);
        void addNext(Activity from, Activity too){
            if(from.outEdges == null){
                from.outEdges = new Edge(too);
                from.outEdges.append(new Edge(too));
            }else{
                from.outEdges.append(new Edge(too));
    }

  • Pseudocode help

    PSEUDOCODE... i got the following pseudocode:
    This is what iv got done but its not looking correct:
    apart from the indentations could someone help me edit it appropriately?
    RoomTest
    driver CLASS
    double roomStore
    Set valid to false
    WHILE (not valid)
    TRY
    New DecimalFormat(&#8220;0.00&#8221;)
    CREATE rectangle1
    Prompt operator for roomW
    Parse roomW to roomStore
    rectangle1.setWidth(roomStore)
    Prompt operator for roomL
    Parse roomL to roomStore
    rectangle1.setLength(roomStore)
    CREATE rectangle2
    Prompt operator for roomW
    Parse roomW to roomStore
    rectangle1.setWidth(roomStore)
    Prompt operator for roomL
    Parse roomL to roomStore
    rectangle1.setLength(roomStore)
    Print &#8220;Room Area Calculator Program&#8221;
    Print &#8220;****************************&#8221;
    Print rectangle1 width
    Print rectangle1 length
    Print rectangle2 width
    Print rectangle2 length
    Print &#8220;Room1&#8221;
    Print rectangle1 width, length, area
    Print &#8220;Room2&#8221;
    Print rectangle2 width, length, area
    Print "************End of program************"
    Valid = true
    CATCH (NumberFormatException)
                   Display error message
              END
    END
    END
    Room
    PRIVATE variables width and length
    Set width to 0
    Set length to 0
    VOID setMethod
    Set width to objectWidth
    END METHOD
    VOID setMethod
    Set length to objectLength
    END METHOD
    DOUBLE getMethod
    RETURN width
    END METHOD
    DOUBLE getMethod
    RETURN length
    END METHOD
    DOUBLE findAreaMethod
    Set roomArea to 0
    roomArea = width * length
    return roomArea
    END METHOD
    END
    Could someone is possible maybe edit it appropriately please?
    Thanks

    Why not continue in this thread:
    http://forum.java.sun.com/thread.jspa?threadID=5120469
    I asked you a question there.

  • Pseudocode for a method

    Write a pseudocode for a method that inserts
    a new node to the end of a doubly linked list. Please give me ashort example.
    thank you

    Post what you have done already and we can point you in the right direction should you need it.

  • Unable to update Jist in gui!!! here s the pseudocode. neglect earlier post

    package test;
    public class newdialog extends JDialog {
    JList and JScrollpane decalred here
    private void jbInit() throws Exception {
                        list initialised here and added to scrollpane
    public static void main(String args[])
    SwingUtilities.invokeLater(new Runnable(){
    public void run(){
    call jbinit() here
         //Takes care of delete action
    private class DeleteListener implements ActionListener{
    public void actionPerformed(ActionEvent e) {
    //gettin new list here and updatin jlist
    //workin fine till here
    //but not updated in gui!!!
    //what seems to be the problem??
    //This is how i m tryin( wit all possible methods)
    scrollPane.revalidate();
    scrollPane.repaint();
    scrollPane.updateUI();
    tabbedPane.revalidate();
    tabbedPane.repaint();
    jList.updateUI();
    jList.revalidate();
    }

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/list.html]How to Use Lists

  • Oracle : Flow for the Concep and Pseudocode

    Hi,
    Consider there are 4 jobs A,B,C and MAIN.The MAIN Job will call other subroutines based on the some condition.The Main Job will call the Job A on the first business day of the every week.also it will call JOB B on every business day.Also it will call the Job C on the first day of the every month. Can anyone suggest me the flow to do it?
    I am using oracle 10g

    Hi,
    You do not need the MAIN job. You just need to create 4 scheduler jobs which each have a different schedule. See the Scheduler chapter of the Administrator's guide or the dbms_scheduler package documentation for help in setting up the exact schedules you need.
    If you really want a main job, create a single main job which runs daily and then spawns the other tasks based on what day it is. You can have the other tasks be single one-time jobs if you want extra parallelism or just have the code inline in the main job
    Hope this helps,
    Ravi.

  • * pseudocode help if possible!!

    Hi.
    I could really use your help on this.
    TY!
    http://i13.photobucket.com/albums/a267/spauldingchris/File0001.jpg

    I don't even know why they offer Java courses at colleges. Students see it and think it will be like other classes (something that they have a chance in hell of understanding let alone passing).
    I think Java 101 is the "flunk course" for computer science majors.
    Like calculus is for business majors.
    That way they know everyone will not pass and it will lend credability (in theory) to the degree.

  • Javascript  - is there something like an "active row count" property??

    Lets say I have a tabular form. Every time I use the form, the # of rows returned by the query will vary. Maybe first time I go to the page, the select statement returns only 5 rows, but the next day it returns 25 rows.
    Is there some type of system variable to stores the # of rows visible on the page at a given time within this tabular form?
    I realize that if I have an tabular form item with an id of f03 for example, then on each row it will be referenced as f03_0001, then f03_0002 on the next row and then f03_0003 on the next row etc...
    In pseudocode, here is what I want to do:
    For i = 1 to ACTIVE_ROW_COUNT (assuming this is the # of rows in the HTML table)
    perform some operation on 'f03_000' + ACTIVE_ROW_COUNT
    Do you see what I'm after? I checked the APEX api, but I couldn't find such a property. It seems like you can't do much if you can't figure out this current index # or the max on the page.
    Also, I tried playing around with the "this" keyword in hopes of finding a pointer to the "current item" that would have triggered the onchange event, but no luck either.
    Thanks in advance.

    Hi:
    Within javascript you can reference the columns of the tabular form as
    <script>
    col1 = document.forms0.f01;  // the first updateable column of your report
    alert (col1.length) ;   //  number of rows
    </script>varad
    Edited by: varad acharya on Dec 8, 2008 5:53 PM

  • How do i transfer funds from one account to another in the same table?

    Say for example i want to transfer funds from UserID 1111101 to UserID  1111103.
    Anyone know the procedure for this. I use php/mysql and dreamweaver.

    Here's a very basic method. Note that this is just pseudocode - you'll need to work out the actual code (I assume you've learned how in your course studies). Keep in mind this is a very simplified workflow - a real bank transaction would be MUCH more complex.
    Create a form that has fields for debit account, credit account, amount
    In your script, assign the values from the form to local variables
    $debit_acct
    $credit_acct
    $amount
    I'll assume you have an account balance table 'acct_bal'. Have a journal table to store those values along with the date and autonumber transaction id.
    Begin Trans
    INSERT into journal (credit_acct, debit_acct, amount, trans_date) VALUES ($credit_acct, $debit_acct, $amount, NOW())
    Get the transaction_id ($trans_id) from the INSERT statement- the method depends on which MySQL interface you are using.
    UPDATE acct_bal SET balance = (balance + $amount) WHERE acct_id = $debit_acct
    UPDATE acct_bal SET balance = (balance - $amount) WHERE acct_id = $credit_acct
    Rollback on any SQL error else Commit Trans.

Maybe you are looking for

  • Inconsistent Data In R/3

    Hi Guys,          I have issue with S039. I am trying to pull the records from S039 like this is designed based on MC.9.          I found all the fields which I need for my requirement and I created generic extraction based on S039. I finished all  r

  • Acting Up Action

    Hi , Can somebody tell me about acting up action. What will be infotypes to be maintained. secondly i have a confusion which i tried to solve through sdn threads but yet not mu ch clear that during organisational re assignment is it neccessary for pe

  • Same icons for objects in SQL Developer as Data Modeler

    Hello, would it be possible to display the same icons for objects in SQL Developer as Data Modeler? For example: - in SQLD a session temporary table has the icon of a table with an X symbol, in Data Modeler it is just a table icon. - in SQLD a materi

  • Xrandr not supporting old resolution

    Upgrading Xorg completely broke my system. Lots of not-fun later, I found out that setting up dual-head has to be done with xrandr, which seems like a good way to do it. However, xrandr does not support setting the resolution from before... I want to

  • Ad-hoc for ipod touch with internet

    Hi, I'm trying to forward the internet to my ipod touch. I believe I've gotten the ad-hoc network itself to work properly, as the ipod claims to be connected, but it cannot use the internet. I've looked at https://wiki.archlinux.org/index.php/Interne