Write a function written in Java and constructs a control flow graph (with a min
ID: 3693736 • Letter: W
Question
Write a function written in Java and constructs a control flow graph (with a minimum or reduced number of nodes) of the input java code. The function must handle at least the following statements and features with any depth of nesting:
1.Assignment statement and arithmetic statement
2. Simple logical expression and composite logical expression of two conditions (or Boolean values). A logical statement may appear as a condition (for If, While, and For), or in a logical expression.
3. If then and If then else statements
4. While statement
6. Read and Write statements( you may assume only one type of each read and write statements)
7. Comment statement
Explanation / Answer
import java.util.*;
class basicTest
{
public static void main(String args[])
{
int i=1,a=10, b=20, c,f=1;
//Displays addition of 2 numbers
System.out.println("Addition of 2 numbers is = "+(a+b));
//Accepts number from user
Scanner scan = new Scanner(System.in);
System.out.println("enter number");
c=scan.nextInt();
if(c>=0)
{
//calculating factorial
while(i<=c)
{
f=f*i;
i++;
}
}
else
{
f=0;
}
System.out.println("Factorial of given number is "+f);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.