0

I am coding in IntelliJ IDEA and my code won't run because of a bug.

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {

    String[] names = new String[5];
    Scanner sc = new Scanner(System.in);

    for (int i = 0; i < names.length; i++) {
        System.out.print("Input: ");
        String input = sc.nextLine();
        names[i] = input;
    }


    for (String n : names) {
        System.out.println(n);
    }
}

}

It says in line 7

Scanner sc = new Scanner(System.in);

Reliance on default encoding Found a call to a method which will perform a byte to String (or String to byte) conversion, and will assume that the default platform encoding is suitable. This will cause the application behaviour to vary between platforms. Use an alternative API and specify a charset name or Charset object explicitly.

I use UTF-8 for my Global Encoding and windows-1252 for my Project Encoding, I use JDK 11 for IntelliJ. I was never encountering any bugs like this until I uninstalled and installed IntelliJ earlier. I also tried the code in an online compiler named JDoodle and it wasn't working, but I ran the code in another online compiler named Programiz and it didn't have any bugs.

p.s. I am still a novice and I don't know what to do.

Kurt
  • 1

0 Answers0