0

I am running the following code on Eclipse with no errors. When I am trying to do the same with Pico compiler app on my Ipad I get 4 types of errors. The print screen are attached. Any idea why cannot running in the same way?

The code:

"''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

import java.util.Scanner;

public class switchClass {

    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    System.out.println("Please enter a command: ");
    String text = scanner.nextLine();
    scanner.close();
    switch(text) {
    case "start":
        System.out.println("Machine started");
        break;

    case "stop":
        System.out.println("Machine stopped");
        break;  

    default:
        System.out.println("Command not recognized!");
    }

    }

}

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Pico Compiler for Ipad running the code :

enter image description here

Pico Compiler errors :

enter image description here

Arnaud
  • 17,229
  • 3
  • 31
  • 44
  • 5
    As far as I know, switching `String`s was introduces with Java 7. Maybe your version of the Pico Compiler does not (fully) support Java 7? – Turing85 Apr 21 '17 at 12:47

1 Answers1

1

The Error says that you can't use a String in the case.

Using String in switch was introduced in Java-7 and therefore, I suspect Pico Compiler uses Java-6 or below.

Fix: Use string in switch case in java

Community
  • 1
  • 1
dumbPotato21
  • 5,669
  • 5
  • 21
  • 34
  • Thank you for the answer. Most probably that's the cause. As I am currently learning Java and mostly is easy to have my tablet instead of the laptop with me all the time, can you recommend an online compiler which can support current java version? – Sorin Magureanu Apr 21 '17 at 13:22