Desired Output:
Data Type: int
Variable Name: a
Initial Value: 0
Conditional Operator: !=
Conditional Value: 5
Increment/Decrement: ++
Interval: 1
for(int a=0;a!=5;a+=1)
{
}
for(int a=1;a!=5;a+=1)
{
}
for(int a=2;a!=5;a+=1)
{
}
for(int a=3;a!=5;a+=1)
{
}
for(int a=4;a!=5;a+=1)
{
}
If you change the interval to 2, it should output "Infinite Loop! Try Again" and if you change the interval to 1, it should output the desired output stated above.
My program's output:
Data Type: int
Variable Name: a
Initial Value: 0
Conditional Operator: !=
Conditional Value: 5
Increment/Decrement: ++
Interval: 1
Infinite Loop! Try Again!
My code:
else if(inc_dec.equals("++") && conditionalOperator.equals("!="))
{
for(float c=initialValue;c!=conditionalValue;c+=interval)
{
if(initialValue == conditionalValue)
System.out.print("for("+dataType+" "
+varName+"="+c+";"+varName+conditionalOperator+conditionalValue+";"
+varName+"+="+interval+"){\n}\n");
else break;
}
System.out.println("Infinite Loop! Try Again!");
}
P.S. The code should only use if-only statements
Aucun commentaire:
Enregistrer un commentaire