I have attempted to complete the following exercise however the output isn't as expected.
You should print a number of pluses equal to the number entered by the user, followed by a list of numbers, so that in total exactly 20 characters are printed. The numbers printed should be the last digit of the current position in the list. Example: +++++678901234567890 if the number entered by the user was 5.
Here's my code:
package interact;
import java.util.Scanner;
public class Interact {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
{int value,k
for (int i=0; i<num1; i++) {
System.out.print("+");}
for (int j=0; j<20-num1; j++) {
if (num1>9) {k=num1-10;}
else k=num1+1;
System.out.print(k);
}
}
The output if 6 is entered is ++++++77777777777777. The numbers aren't incrementing - why not?
Aucun commentaire:
Enregistrer un commentaire