Xiaobai on the System.out.println problem

1,


import java.util.*;  

public class Main {

    public static void main(String[] args) {
        int[] arr=new int[4];
        Scanner in=new Scanner(System.in);
        for(int i=0;i<4;iPP){
            arr[i]=in.nextInt();
        }
        
        for(int i=0;i<4;iPP){
            System.out.println(arr[i]+"\n");  //
        }
        
    }
}

run result:
clipboard.png
question: why is each number added by 10?

Jun.17,2022

arr [I] +'\ n 'belongs to an int type plus a char. the process is that the char type is first promoted to the int type (the ASCII value of'\ n' is 10), and then added to the int type, which is why the result is 10 more.
println has its own line wrapping feature, so there is no need for\ nline feeds.


'n 'decimal equals 10

Menu