dimanche 10 janvier 2016

Java if - else return error "String cannot be converted to int"

I think I might be completely wrecking the Syntax of a method I am trying to create. The method is part of a larger application that gets the user information to make an invoice.

I get the following error for whatever reason:

java:43: error: incompatible types: String cannot be converted to int

Any help is deeply appreciated!

Here is the latest version of code I have tried:

public static int inputmethod(String question){

Scanner in=new Scanner(System.in);
System.out.println ("Input " + question + ":");
int s=in.nextInt();
String x = "Wrong, value cannot be 0, please try again!";
if (s==0) return x;
else return s;
}

Aucun commentaire:

Enregistrer un commentaire