java - Adding repeating integers in a "for" loop a specified number of times -
i looking way run "for" loop start user defined value "d" (between 1 , 7) , add 1 continuously until reaches other user defined value "n". here's catch...i need repeat count "1" once value "7" reached without being stuck in infinite loop.
for example, program prompts user input 2 numbers , stores them "d" , "n" respectively. first number can "1-7" , second number can anything. so, if user inputs "5" , "10" need loop start counting @ "6" , count "10" times, starting on @ "1" once value has reached "7". should this... "6 7 1 2 3 4 5 6 7 1".
right have looking this... "6 7 8 9 10 11 12 13 14 15"
this current code , output "5 = d" , "10 = n"
code
public void incrementday3() { int i; for(i = (d + 1);i <= (d + n);i++) { system.out.print(i); } } output
"6789101112131415"
any appreciated!
try (modulo operator) :
public void incrementday3() { int i; for(i = d ; < (d + n) ; i++) { system.out.print((i % 7) + 1); } } for more information modulo is, can check wikipedia article
Comments
Post a Comment