如何在java中构建def循环? [英] How do I build a def loop in java?

查看:58
本文介绍了如何在java中构建def循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的读者,



我原来是一名python程序员,但由于我需要学习java的原因。我还在学习,我犯了许多基本的错误,因为我不时地用python迷惑自己,对不起。下面你可以找到一个基于文本的冒险,我在python中写了这个很棒!但是为了学习java我在java中重写它,但是我很难,而且我不理解所有的错误。我习惯做一个def并让python程序循环遍历几个,直到有一个中断或退出(我称之为def循环,但是如果它是其他东西则纠正我)。我希望你能理解我下面尝试做的事情。



我期待着回复



-Sjoerd







Dear reader,

I am originally a python programmer, but for reasons I need to learn java. I am still learning and I make a lot of basic mistakes because I confuse myself from time to time with python, sorry for that. Below you are able to find a "text based adventure", I wrote this in python which worked great! but to learn java I am rewriting it in java, however I am having a hard time and I do not understand all the errors. I am used to make a def and let the python program loop through several until there is a break or exit (I call them def loops, but correct me if it is something else). I hope you are able to understand what I tried to do down below.

I am looking forward for a reply

-Sjoerd



import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;

public class AppTest {
	
	public static void main(String[] args) {
	
		String[] tekendoos = new String[] {"ckv module"};
	
	
	public void Start(tekendoos) {
		System.out.println("[-De lift van WIM Inc.-]");
		System.out.println("1.) niveau 1 - Wims loerhokje");
		System.out.println("2.) niveau 2 - Juuls onderhoud station");
		System.out.println("3.) niveau 3 - Sjoerds archief");
		System.out.println("4.) niveau 4 - Adries gymzaal");
		System.out.println("5.) niveau 5 - Henks kantoor");
		System.out.println("6.) niveau 6 - Aula");
		
		List<String> cmdlist = Arrays.asList("1", "2", "3", "4", "5", "6");
		cmd = GetCmd(cmdlist);
		
		if (cmd.equals("1")) {
			System.out.println("test");
		}
		else if (cmd.equals("2")) {
			System.out.println("test");
		}
		else if (cmd.equals("3")) {
			System.out.println("test");
		}
		else if (cmd.equals("4")) {
			System.out.println("test");
		}
		else if (cmd.equals("5")) {
			System.out.println("test");
		}
		else if (cmd.equals("6")) {
			System.out.println("test");
		}
			
		
	}
	
	
	public void Onderhoud (tekendoos) {
		
	}
	
	public void GetCmd (cmdlist) {
		Scanner toetsenbord = new Scanner(System.in);
		String Help, Tekendoos, Stop;
		
		System.out.print("Sjoerd:> ");
		cmd = toetsenbord.next();
		
		if (Arrays.asList(cmdlist).contains(cmd)) {
			return cmd;			
		}
		
		else if (cmd.equalsIgnoreCase("help")) {
			System.out.println("typ: 'tekendoos' om te kijken wat je hebt");
			System.out.println("of 'stop' om op te geven, dan ben je echt zwak");
			System.out.println("of 'ckv module' om je geest op andere wezens aan te sluiten");
		}
		else if (cmd.equalsIgnoreCase("tekendoos")) {
			System.out.println("je bekijkt je tekendoos");
			System.out.println(Arrays.toString(tekendoos));
		}
		else if (cmd.equalsIgnoreCase("stop")) {
			System.out.println("Je benaderd het spoor");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Je ziet het gele licht");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Je kopt de trein");
			TimeUnit.SECONDS.sleep(2);
			System.out.println("Stef is trots");
			TimeUnit.SECONDS.sleep(2);
			System.exit();
		}
		
	}
	
} 

}





我尝试了什么:



我已阅读了大量文档,但每当我想修复它时,我都做了一些pythonic的东西只会让它变得更糟。



What I have tried:

I have read a lot of documentation but whenever I thought to fix it, I did some pythonic thing which only makes it worse.

推荐答案

转到 Java™教程 [ ^ ]并完成教程。这是获得良好的语言基础的最佳方式。
Go to The Java™ Tutorials[^] and work through the tutorials. It is the best way to get a good grounding in the language.


这篇关于如何在java中构建def循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆