Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output int from array in java increases the integer value [closed]

Tags:

java

Can someone explain why, when I input values, the output is increased by 9, for all the values stored in the array?

    int [] number;
    int numCounter,num;

    userInt validate = new userInt();

    //set the number of array it can hold
    number = new int[100];
    //set the counter to be equal to zero;
    numCounter = 0;
    validate.InputString("enter up to 100 positive integer;");
    while(true){
        validate.InputString("enter 0 to end");
            num = validate.userInt();
                //this will exist the loop statement
                if(num <= 0)
                    break;
            number[numCounter] = num;
            numCounter++;
    }

    //this will print the enter number from the array in reversed order
    for(int i = numCounter - 1; i >= 0; i--)
        System.out.println(number[i] +'\t');
}
like image 496
Terrymight Avatar asked Jun 24 '26 09:06

Terrymight


1 Answers

You are adding the int value of the tab character to each number, which is 9.

System.out.println(number[i] +'\t')

If you want to print a TAB after each number, change to :

System.out.println(number[i] + "\t");
like image 171
Eran Avatar answered Jun 26 '26 22:06

Eran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!