Making a Prime Number with a Flow Service

Hi everyone, so I tried to implement the code from here Prime Number Program in Java - Javatpoint to flow service.

1

Here is the result that I get when I input “1” which is true
2

But when I input number than 1, this is the result
3

Does anyone can help me to fix the problem?

How do I solve this?

I’m struggling to follow your second result screenshot - can you cleanup your variables (link) and give them meaningful names?

Variable-naming and cleanup discipline is paramount for a developer.

The Java code was easier to follow - your flag is 0, so it means that 10 is not a prime number.
Check if you’re populating the “message” field in all the debugLog steps.

P.S - It looks like you replicated the code without understanding what it is doing (particularly the logic under Repeat). Use the “debug” functionality on Designer, to follow the variables and the flow.

KM

1 Like

Hi, Mr. Kasi thanks for answering,

Thank you for the reminder to clean my variables name, I will do that.

About the “message” field, I’ve put all the values that I want to be printed but still don’t get an output.

Your second Branch is set up as a Switch, but you’re evaluating a condition as an If-Else construct. Can you update the “Evaluate Label” parameter to “true”, just like in your first branch?

Also, both the conditions on output have “=” on them - you need to correct that as well.

KM

1 Like

I’ve put my evaluate label parameter to true in my second branch but still doesn’t work

image

About the “=”, to what should I change?

Thanks

It’s difficult to investigate it this way; export and attach your package so I can take a closer look.

KM

1 Like

Here is the FLOW service that I make

testing2.zip (4.9 KB)

And this is for the modulo java service that I make if you need it.
modulo.zip (1.5 KB)

Thank you for seeing this

Ghifari, I’ve reviewed this -

  • Input variables are dropped even before they’re used
  • Java service is not functional because “input” and “i” are used as service inputs but also being reinitialized again so your modulus operation does not work
  • Second branch is being used incorrectly
  • “m” is configured in Repeat as a counter but it’s not available in the pipeline
  • “flag” variable is initialized because it’s available in the Java snippet, but it has no use
  • for ( i=2 ; i<=m ; i++)” is a comment and not the coding logic (Flow doesn’t work like that)

Based on my comments above, here’s some straightforward feedback to you -

  1. You are not ready to build Flow or Java services, yet
  2. Fundamentals - Understand what each Flow operation is meant for and how to use them
  3. Understand what is that you are trying to solve, before you write code - if you don’t understand the math behind how to determine a prime number, you cannot build a service to solve that problem
  4. Start with simple flow services - for example, math operations, calculator, etc.
  5. Familiarize yourself with the concepts of writing a Java service in IS - they are trickier than Flow
  6. Use the “Debug” and “Step” features to step through your flow to see how your variables

Forums are to help you get past an obstacle, but not at this fundamental level.
You are new to this, which is perfectly fine - we all started at zero at some point. However, without understanding the fundamental building blocks, you are not going to move forward.

Public Courses -

Documentation -

I wish you the best!

KM

2 Likes

Thank you so much for the precious feedback Mr. Kasi Mugada.

Here are some of my comments on your feedbacks:

  • I know the for ( i=2 ; i<=m ; i++) is a comment, that’s just a little reminder to me
  • I’ve started with a simple flow service like what you recommended to me, and it works as expected

I don’t know if it okay or possible, but can I have a request about how the flow service should be for the prime number? I’ve successfully recreated @Mahesh_K_Sreenivas flow services regarding Fibonacci sequence from here Creating a fibonacci sequence Service Flow - #3 by Mahesh_K_Sreenivas

I think I will learn quicker if there is an example, and learn how the process went from the debug.

I would be soooo thankful if you can make an example for me about the flow for prime numbers.

Have a nice day sir.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.