Error "required int" when executing code

Asked

Viewed 61 times

0

I made this small program, where I want you to loop, while the user chooses to register more messages.

The error, after compiling the code, says:

required:int
found: no Arguments
Reason: actual and formal argumente lists differ in lenght.

Here is the code snippet:

/*
 * Class do registo de mensagens
 */
import java.util.*;
public class RegistoDeMenssagem1 
{           
   public static void main(String[] args) 
   {  
       System.out.println("Bem vindo Utilizador"); 
        System.out.println("Introduza o número da recarga"); 
        Scanner kb = new Scanner(System.in);
         int Recarga = kb.nextInt();  //criar o mêtodo que verifica se trata-se de int.
        String resposta;
        boolean sn;

     {
    System.out.println("Têm mais recarga para registar?");   
    System.out.println("responda `S´ para continuar ou `N´ para terminar");
     resposta = kb.nextLine().trim().toLowerCase();
    if (resposta.equals("s")) 
        {
            sn = true;
            System.out.println("Introduza o número da recarga"); 
            Scanner kb2 = new Scanner(System.in);
            int MaisRecarga = kb.nextInt(); //Aqui criar o exception handler que verifique tratar-se de int.
        System.out.println("Têm mais alguma recarga para registar?");   

    } 
    else if (resposta.equals("n"))
        {
            System.out.println("Obrigado, atê a próxima!");
                System.exit();
    }
     }

   }
}
  • 1

    In which line the error bursts?

  • error bursts in java:32

  • And what is line 32 of this code?

  • Line 32 of the code is: System.Exit();

  • Good morning friend, the method Exit(), receives a parameter of type int, so the error, tries to use System.Exit(0);

  • I managed to solve the error but not my problem. that is, I intend that by the option "n" the program make a loop. Thankful.

  • @cambine as doubt was about error, the question has even been answered, the advised is that you create a new question informing the other problem you are facing. You can accept one of the answers below as well, to mark this problem(the error) as fixed.

Show 2 more comments

2 answers

3

The static method call System.exit(int status) requires that a type be passed int as argument, which identifies the type of execution termination status.

If the breakup was normal(not because of some exception or other unforeseen situation), you can pass 0 as argument. If there was an error, you can pass another value other than zero.

Change this line to System.exit(0);, since by your code, the problem is normally ending.


References:

2

  • 1

    Thank you. Holy stupidity was mine.

  • 1

    It’s not your stupidity, you’re right to take your doubt

Browser other questions tagged

You are not signed in. Login or sign up in order to post.