Menu
Question Index
...

What will be the output of the following program?

class Procedure {
    public static void main(String[] args) {
        String in = "198";
        int n = 5;
        while (n > 0) {
            char[] line = in.toCharArray();
            int i = line.length - 1;
            if (line[i] % 2 != 0) {
                line[i]--;
            }
            System.out.print(line);
            System.out.print(" ");
            n--;
        }
    }
}


198 188 178 168 158
198 197 196 195 194
197 197 197 197 197
198 198 198 198 198
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Character Extraction - toCharArray() Method In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App