How to reset a variable after each iteration of a loop?

Here's the code if you need to see. 'fact' is what I want to zero whenever the factorialN method completes. Thanks in advance.
import java.util.Scanner;

public class Factorial {
     static int fact = 1;
     static int newNum = 0;
     /**
      * @param args
      */
     public static void main(String[] args) {
          // TODO Auto-generated method stub
          char answer;
          do {
          System.out.println("What is the number? ");
          Scanner keyboard = new Scanner(System.in);
          int num = keyboard.nextInt();
          factorialN(num);
          Factorial aFactorial = new Factorial();
          System.out.println(aFactorial);
          System.out.println("Do you want to continue? y/n ");
          String answerString = keyboard.next();
          answer = answerString.charAt(0);
          }
          while (answer == 'y' || answer == 'Y');

     }
     
     public static void factorialN(int num) {
          while (newNum < num) {
               newNum ++;
               fact = fact * newNum; }
     }
     public String toString() {
           String returnValue = "Its factorial is " + fact;
           return returnValue;
        }
}

What is the problem? Declare the method as "int" instead of "void" and the return value.

Tags: Java

Similar Questions

  • How to save a graph after each iteration in a loop for?

    Hello

    I wrote the code that initializes a spectrometer. Once initialized, if the "Capture" button is pressed, the spectrometer takes a new spectrum three times (see loop for) every second. This spectrum is shown as a diagram in my front. My code works fine... it will update the spectrum every second.

    However, I would like to be able to record each of these three iterations in the form of separate graph. Basically I want to click on "Capture" and have my code to save three graphics to a specified folder. How can I do this?

    I have attached my VI.

    Thank you.

    Probably the easiest is to take the data of the for loop and pass out in a tunnel that is indexed.  Manipulate the resulting data table you want.  You could also do a producer/consumer and write files as the data comes out.

  • How to reset the counter at each iteration, and how to introduce a delay

    Hello world

    First of all I apologize for the basic level of my questions, I'm new with Labview...

    I'm counties of reading out of a USB-6008 labview chip using the DAQ assistant and I write the output to a file. The problem is that instead of giving me the number of levels for each iteration it gives me the sum of all this. How to make Wizard Reset to 0 data acquisition account on each iteration? I tried using a shift register, but it added a counter to my folder and nothing else...

    Thank you very much

    Sure thing. Sorry about that.

  • How to upgrade a table after each iteration?

    Hello

    I have a vi which works fine but the problem is that it updates all the data once the vi stops running. I want something as soon as (for outside for loop) 1 iteration it performs updates the table in front of the Panel, then 2nd iteration, it updates again and so on. Can anyone help me please with this.

    Thank you

    In fact, in your case, there are a simpler way to do it... If we talk about the pink channel on the first loop indicator.

    Just move the table from outside the loop inside the loop indicator.

  • How insert elements into a table after each iteration of a for loop

    I'm new to labview and work on an application where I'm supposed to store an element in an array (without crushing) after each iteration in a loop for. I tried using function Array build, keeping the flag outside the loop for and played with indexing, but did not work. Please suggest me an idea how to do it.

    Thank you

    It would be better if you attached the real VI.

    None of your images show an operation 'insert into array.

  • How to read the data processed on frm loop on each iteration of the loop?

    Hello...

    I need to display numbers as 1, 2, 3... constantly using the loop on each iteration (IE out of the loop using threads). I generated the numbers 1 2 3... using the back power node... I can read the final value after the last iteration of the loop for.

    I connected an indicator of the loop for. This indicator displays the value as a 4 If the number of loops that 4. I couldn't view 1 2 3 4 an indicator of items at each iteration.

    I'm in a position to read the value of the variable on each iteration of the loop. Please help me fromthis regard...

    Thanks in advance...

    In fact, I'm programming for multiplication of two table 2D.

    I need to select the particular code to perform this action using the structure of the case. who is right for which I need to give the value select 1,2,3 to a case selector, so I finish the task. you got my point?

    Thanks for the reply

  • A generated within a loop in a subvi output data can be transferred to the main program for each iteration of the loop?

    Hi LV users,.

    I have a very basic question, I have not succeeded to asnwer using basic considerations.

    I made a sub - vi that performs a scan of current-voltage using a unit of measurement-source Keithley and a loop FOR.

    The subvi outputs 2 tables with my data (essentially an array of voltage and the corresponding current table). I also defined a Terminal at the exit of a group of these 2 tables in order to plot a graph XY - output. Specifically, I indexed this cluster to update after each iteration of the loop FOR, in my sub - vi (the indicator is placed outside the loop, of course).

    My problem is that I want my main program to display the XY-graph in real time, with an update after each iteration of the loop FOR which is in my sub - vi.

    I have a problem because my sub - vi output terminals are available for the main program concluded as soon as the sub - vi has completed its own execution (which is what we expect of sub - vi to do).

    How can I use a sub - vi (because it's handy) and get in the main program in the course of its performance data that are generated from the loops of sub - vi?

    Thanks in advance for your help,

    Yoyo87

    Elements of the queue in the Subvi them put your main VI where you want to display the data and the.

    It is similar to the architecture of producer/consumer. There are examples of it in LabVIEW. The examples work with 2 parallel loops, in your case a loop (the producer) will be in the Subvi.

  • How do you give each iteration of a loop IF %

    Subject: Send a signal to step to a stepper motor driver at regular intervals.   My first try to use a loop was a failure because the data is only passed on a loop when the loop ends.   Instead this application requires the data to be passed on a loop on each iteration.

    What happens if changes can be made to a loop for output at each iteration?  Or, if a loop is not suitable for this application which is preferable?

    Howard

    A loop looks like a reasonable approach. But you will have to send the signal to each iteration of the loop, then talk to the stepper motor inside the loop on each iteration. You can also think of calendar of loop (how fast you want to send commands to your engine) and stop the loop (for example, the user clicks on a stop button).

    Another concept, you can familiarize yourself with are state machines. LabVIEW courses cover these, and there are many messages about the machinery of State here on the forum.

  • reset the graph after each race

    Hello

    In attachment VI, I am trying to collect data to interverals (in seconds) and display them in a chart that updates after each iteration.  However, I like the graph to be handed over to zero just before starting a new would go program.  In the current state, after the end of the program, the graph just seems to add data and continues on.  I would like to have the x-axis as time.  In the current state of the program, I wait 1 second, take the data and so on.  I would like a parcel of time data vs.  So in the attached VI, the graph must finish 20 sec.

    Honestly, I'd appreciate any help to determine my dilemma.  I'm under LabView 8.2.

    Thanks for all your help and your time.

    hiNi.

    Like this

  • plot update after each iteration

    Hello

    I have an example of data code where I collect data on different devices.  Can you help me to update "GRAPHIC 2" to display all of the plots on this graph."  However, I would like FIGURE set 2 updated after each throw outside of the loop.  [After the 3rd iteration of the outer loop (defined by "outer loop"), "GRAPH 2' should therefore 3 plots and so on..."]

    Thank you

    hiNi.

    Hello hiNI

    Do you want something like that?

  • How to reset a variable when refreshing a report interactive

    Hello

    Maybe a simple question but I can't find the answer.
    I have an interactive report in which I can highlight a row. In doing so, I put a variable using a javascript function declared in the html header.

    My problem is when I refresh the report. I have no more line selected by my variable is always set to the previous value. How can I reset the variable during the updating of my report?

    Concerning

    975489 wrote:
    Indeed, sorry about the lack of information.

    My platform is composed of:
    * Full APEX version: 3.2.1.00.12
    * Full DB/version/edition/host OS: oracle 11.2.0.1 std edition on linux x 64
    Web server architecture: APEX listener/linux x 64
    * Browser (s) and used versions: IE, chrome,...
    and "variable" means indeed for me a page element.

    Proposal seems quite applicable on apex 4 and I can't find reference to elements of the Page to submit.

    Concerning

    3.2, it is under the attributes report > Advanced attributes section

    See http://docs.oracle.com/cd/E14373_01/appdev.32/e11838/app_comp.htm#BABEEABE

    Thank you
    Vikram

  • How to stop automatic download after each time that you buy a property?

    I would like to know if there is a way to stop an application being downloaded automatically after each purchase?

    Welcome to Apple Support communities

    If I'm not wrong, you want to disable automatic downloads (the feature that automatically downloads all content you purchase all your devices), right? If this is the case, there are different ways to disable depending on the device that you are using:

    • For iOS: go to settings-> iTunes and App Store (or App Store), then disable everything under "automatic downloads.
    • For PC and Mac: open iTunes, go to Preferences (in the iTunes menu on a Mac) or edit on a PC-> Store menu and disable everything under "automatic downloads.
  • Graph waveform repeats with each iteration of the loop

    Hi guys,.

    I got some great responses from you many already, so I hope you can help me once more!

    I try now to simply take a voltage that is measured by a sensor, I tied to AI1, and I built a graph of very simple waveform using a DAQ assistant. I have the setup terminal to CSR, the acquisition value continuous sample mode and read samples and rate game to a control on the Panel before which I can control myself. All this is a while loop that is needed to collect data over time.

    However, the problem I have is that for each loop of the loop, it seems, to reset the graph, so my x-axis never increases over time, ideally I want it to do is to show results through from 0 to 100 on the x-axis to say, and then, when it comes to 101, he will start again on the extreme left of the graphic to the right to a crossing another 100 points given) (there's a term for this, but I forgot, sorry!). To be honest, this kind of logic like everything in the loop will be restarted, but after trying to chart the loop it does not work, so I'm fresh out of ideas.

    I think I might have to do is to manually build segments of data acquisition (DAQ mx) and have only certain parts of them in the loop, although I can't be sure. I tried various examples and online on the database of NOR (including tension-int acq & graphic clk which works well in the examples, but not at my request) but no luck for now

    If anyone can think of what could be the problem, then please let me know. FYI the sensor is optical fiber if it makes a difference. I have attached the file VI that I did does not really...

    See you soon!

    Ritchie

    Since you use a chart there is no way to fix it. If you choose to go to a XY chart you could solve this problem. See the example below.

  • How to reset the chart after a task?

    Hello

    I use the structure of event producer consumer for my problem, in this case everything works well but I am facing problem after surgery when I press RUN again after having competed a chart of operation does not reset correctly sound also display old measurement simultaneously.

    I want to reset it completely and to display the reading for the new task only.

    Even in the file that is saved after execution of a task is also has a problem that I have his backup data twice in the same file I want.

    How to solve this problem guide please me.

    Thank you very much.

    It asks something much simpler, his problem is not the graph itself - it is simply not resetting (empty) table at the beginning of each case "default".  That's all he needs to do, is attached the vi changed.

    AnkitRamani - as I said in another thread, you must clean your programming (small steps at a time) - functionality of your code is made quite clumsy, you can do all this in a much smaller cleaner LabVIEW code, even if you examine and draw a few relevant examples.

    -DP

  • How to reset a variable count in a trigger of conditional formatting

    I use a trigger of conditional formatting to remove the sections of a report where there is no data. The trigger is automatically generated by reports (see below). the condition is: com_count = '0' therefore no record, no display of the section - if: com_count > 0 then given present and display the record.

    It works very well eliminate sections - until the actual data is found - count is set to 1, and it displays the record. The problem is that once: com_count > 0, then the section displays the rest of the report that there is actually data or not.

    It seems that: com_count must be reset to 0, but when I try to do, it generates an error indicating that: com_count is a read-only variable.

    I'm new to the PL/SQL if can anyone suggest how I can reset the: com_count to 0 whenever the lights of relaxation with: com_count = 1?

    Any help would be appreciated. Thank you

    Glenn

    Is the trigger for the conditional formatting:

    function boolean return M_G_COM_RANK_GRPFRFormatTrigge is
    Start

    -Automatically generated from report designer.
    If (: COM_COUNT = '0')
    then
    Return (FALSE) End Function
    end if;

    return (TRUE);
    end;

    The County

    It works perfectly

    where is your COM_COUNT defined?

    If must be defined in the 'mastergroup"of the"detailgroup"which you want to count the records in the datamodel.
    In this case, there is a property of the item "Reset to" (which is by default the option 'Report') and then you can edit it on behalf of the mastergroup. So whenever a new record is 'active' in the mstergroup, the point count will be reset to 0.

    hope this helps

Maybe you are looking for