Java 如何直接从程序中退出

Java 如何直接从程序中退出,java,Java,我面临的错误请帮我整理一下,因为我有我的项目要提交…请 import java.util.*; public class project { public static void intro1() { Scanner obj= new Scanner((System.in)); System.out.println(" This converter will be related as follows" ); System.out.println("

我面临的错误请帮我整理一下,因为我有我的项目要提交…请

import java.util.*;

public class project
{        

public static void intro1()
{
    Scanner obj= new Scanner((System.in));
    System.out.println(" This converter will be related as follows" );
    System.out.println(" 1.Digital Storage" );
    System.out.println(" 2.Distance(length)" );
    System.out.println(" 3.Currency" );
    System.out.println(" 4.Temperature" );
    System.out.println(" Please choose your option,which you want to be converted,please type that number related" );
    int q= obj.nextInt();
    System.out.println(" Command received!....executing..." );
    String w=Integer.toString(q);
    String a=(w.trim());
    int n=Integer.parseInt(a);
    switch(n)
    {
        case 1:
        {
            //some codes here 
        }
        break;
        case 2:
        {
            //some codes here 

        }
        break;
        case 3:
        {

        }
        break;
        case 4:
        {
            //some codes here `enter code here`
        }
        break;

        default:
        {
            System.out.println(" I'm sorry you have chosen the wrong option...please enter again" );
            {
                intro1();
            }
        }
    }
    exit();
}

public static void exit()
{
    Scanner obj=new Scanner (System.in);
    System.out.println("to continue type 'cont' or else type 'exit'");
    String pi=obj.nextLine();
    if(pi=="exit")
    {
        System.exit(0);
    }
    else 
    {
        intro1();
    }
}
}
我面临的错误请帮我整理一下,因为我有我的项目要提交…请

只需替换代码即可

import java.util.*;

public class project
{        

public static void intro1()
{
    Scanner obj= new Scanner((System.in));
    System.out.println(" This converter will be related as follows" );
    System.out.println(" 1.Digital Storage" );
    System.out.println(" 2.Distance(length)" );
    System.out.println(" 3.Currency" );
    System.out.println(" 4.Temperature" );
    System.out.println(" Please choose your option,which you want to be converted,please type that number related" );
    int q= obj.nextInt();
    System.out.println(" Command received!....executing..." );
    String w=Integer.toString(q);
    String a=(w.trim());
    int n=Integer.parseInt(a);
    switch(n)
    {
        case 1:
        {
            //some codes here 
        }
        break;
        case 2:
        {
            //some codes here 

        }
        break;
        case 3:
        {

        }
        break;
        case 4:
        {
            //some codes here `enter code here`
        }
        break;

        default:
        {
            System.out.println(" I'm sorry you have chosen the wrong option...please enter again" );
            {
                intro1();
            }
        }
    }
    exit();
}

public static void exit()
{
    Scanner obj=new Scanner (System.in);
    System.out.println("to continue type 'cont' or else type 'exit'");
    String pi=obj.nextLine();
    if(pi=="exit")
    {
        System.exit(0);
    }
    else 
    {
        intro1();
    }
}
}
if(pi.equalsIgnoreCase("exit"))
    {
        System.exit(0);
    }
    else 
    {
        intro1();
    }
或者你可以简单地添加5.退出并写下以下条件

case 5:
        {
          System.exit(0);
          break;
        }

欢迎来到堆栈溢出!请看和。也看到