My code is
int array[] = {'a',98};
for(int num:array) {
    System.out.println(num);
}
If I print this, I'll get o/p as 97 98.
If I print (char) num then o/p will be a b.
Is it possible to print the array as a 98? My guess is as array will store integer values of the array elements, it is not possible. But any solution here?
I don't think there is any way to do it with int[]. But you can create Object[] to achieve this.
Here is the code snippet:
public static void main (String[] args) throws Exception {
    Object array[] = {'a',98};
    for(Object o : array){
        System.out.println(o);
    }
}
Output:
a
98
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With