-1
好吧,这是我的代码到目前为止,我真的需要帮助,使其退出后,我输入退出,也为程序不键入一个字符串后结束。任何帮助或链接到一些帮助将不胜感激我是一个非常新手的程序员。如何让我的程序在进入退出后退出
import java.util.Scanner;
import java.io.*;
public class reverse
{
public static void main(String [] args)
{
String input = null;
Scanner keyboard = new Scanner(System.in);
System.out.print("Please enter a string for reversal or type QUIT to exit: ");
input = keyboard.nextLine();
if(input.equals("quit"))
{
//close the program
}
Reverser(input, (input.length() - 1));
System.exit(0);
}
public static void Reverser(String str, int size)
{
if(size>=0)
{
System.out.print(str.charAt(size));
Reverser(str,size-1);
}
}
}
将'System.exit(0);'移至'if'条件。 –
DANG,工作idk为什么我想离开它 – akay
如果你希望你的程序能够接受多个字符串,你最好学习循环:'for'循环,'while循环和'do .. .while'循环。阅读关于他们[这里](http://docs.oracle.com/javase/tutorial/java/nutsandbolts/while.html)和[here](http://docs.oracle.com/javase/tutorial/java/对于初学者来说,nutsandbolts/for.html)。 –