简体   繁体   中英

Little trouble in compiling java

i have got a problem while i tried to compile console game, Console shows me

Exception in thread "main" java.lang.Error: Unresolved compilation problem: at Pytania.main(Pytania.java:6)

Line 6 is public static void main(String[] args) , and i sadly dont see fail :(

I use Eclipse, thanks for answer :)

import java.util.Scanner;

public class Pytania{


public static void main(String[] args){

    String Elf = ("Elf");
    String Kot = ("Kot");
    String Wojownik = ("Wojownik");
    String Lucznik = ("Lucznik");

    Scanner pisz = new Scanner(System.in);

    System.out.println("---------------------------------");
    System.out.println("----------RPG--TALES-------------");
    System.out.println("------------Part 1---------------");
    System.out.println("---------------------------------");
    System.out.println(" ");
    System.out.println("Pamietaj, pisz poprawnie, inaczej mutanty wysadza gre! :D ");
    System.out.println(" ");
    System.out.println("Podaj nazwe uzytkownika");
    String nazwa = pisz.nextLine();
    System.out.println("Witaj " + nazwa + " w nowym symulatorze RPG, nastepnym krokiem bedzie wybranie klasy, wybierz klase z dostepnych ponizej");
    System.out.println("Elf, Kot, Wojownik, Lucznik");
    String postac = pisz.nextLine();
    System.out.println("Gratulacje " + nazwa + ", Wybrales klase " + postac);





    if (postac=="Elf"){

        return postac = Elf;


    }


}

This'll help me a lot, thanks ! :)

You can also change your equals method to something like this:

static String equals(String postac)
{


    switch(postac)
    {
        case "Elf": postac = "Elf"; 
            break;
        case "Kot": postac = "Kot";
            break; 
        case "Wojownik": postac = "Wojownik";
            break;
        case "Lucznik": postac = "Lucznik";
            break;

    }
         return postac;
}

And then you can just call it within your final statement just like:

 System.out.println("Gratulacje " + nazwa + ", Wybrales klase " + equals(postac));

You must add another } at the end to close the class definition.

Also, you cannot use a return statement in a void method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM