Hello!

public static void main(String[] args) 
	{
		System.out.println("Type the operation system (Windows or Linux):");
		Scanner oku= new Scanner(System.in);
		String os=oku.next();
		if(os=="Windows")
		{
			CreateForWindows();
		}
		if(os=="Linux")
		{
			CreateForLinux();
		}
		else
		{
			System.out.println("Wrong selection. Program closed.");
			return;
		}
		return;

It always show me Wrong selection. Program closed. I can not understand why it does not go inside on any if block. I printf also the String os to see if it is equals on windows or Linux, which shows me exactly what i type. How that possible so simple thing...

u must use os.equals("");

Its a method for string.

Yes: It is important to always compare strings using the '.equals' method -- not the '==' operator.

(And in Java, the convention is to start method names with a lower case letter. ;-)

There is something to be said for doing the string comparisons like this:

public static void main(String[] args) {
		System.out.println("Type the operation system (Windows or Linux):");
		Scanner oku = new Scanner(System.in);
		String os = oku.next();
		if ("Windows".equalsIgnoreCase(os)) {
			createForWindows();
		} else if ("Linux".equalsIgnoreCase(os)) {
			createForLinux();
		} else {
			System.out.println("Wrong selection. Program closed.");
			System.exit(1);
		}
		return;
	}

Oh! okey...

Thank you so much ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.