eclipse - java - errors

Asked

Viewed 134 times

0

someone can help me find the error of this code

package trab;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class tra {

    public static void main(String[] args) {
        //new janela();//
        Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Brazil/East"));
        int hora = calendar.get(Calendar.HOUR_OF_DAY);
        int minuto = calendar.get(Calendar.MINUTE);

    Scanner s = new Scanner(System.in);
    int [] p = new int [5];
    int [] aux = new int [5]; 
        for (int i=0; i<5;i++) {
            System.out.println("faça seu pedido! as opções de hoje no cardapio são: "
            + "\n 1- X hamburguer de rato "//demora 20 minutos
            + "\n 2- X filé de grilo "//demora 20 minutos
            + "\n 3- X queijo de cobra "//demora 10 minutos
            + "\n 4- X lonbinho de elefante "//demora 40 minutos
            + "\n 5- X vegetariano (a melhor opção ) "//demora 10 minutos
            + "\n 6- sopa de minhoca");//demora 1 hora
            p[i]=s.nextInt();
        }
    merge(p,aux, 0,p.length-1);
    System.out.println(Arrays.toString(p));

        private static void merge(int[] p, int[] aux, int inicio, int fim) {
            if (incio<fim) {
             int meio=inicio+fim/2;
              merge(p,aux,inicio,meio);
              merge(p,aux,meio+1,fim);
              intercalar(p,aux,inicio,meio,fim);
            }

        }
    }

    private static void intercalar(int[] p, int[] aux, int inicio, int meio, int fim) {
        for(int i=inicio;i<=fim;i++) 
            aux[i]=p[i];
            int k=inicio;
            int j=meio+1;


        for(int i=inicio;i<=fim;i++) {
            if(k>meio) {
                p[i]=aux[j++];
            }
            if(j>fim){
                p[i]=aux[k++];
            }
            if(p[i]<aux[j]){
                p[i]=aux[i++];
            }
            else {
                p[i]=aux[j++]
            }
        }
    }

}

when I try to run it appears this message

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The method merge(int[], int[], int, int) is undefined for the type tra
void is an invalid type for the variable merge
Syntax error on token "(", ; expected
Duplicate local variable p
Syntax error on token ",", ; expected
Duplicate local variable aux
Syntax error on token ",", ; expected
Syntax error on token ",", ; expected
Syntax error on token ")", ; expected
incio cannot be resolved to a variable
The method merge(int[], int[], int, int) is undefined for the type tra
The method merge(int[], int[], int, int) is undefined for the type tra

at trab.tra.main(tra.java:29)

1 answer

2

As far as I’m concerned, you have to get the method out: merge(int[], int[], int, int) from within method main(String[] args). As below:

package trab;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
import java.util.TimeZone;

public class tra {

    public static void main(String[] args) {
            //new janela();//
            Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("Brazil/East"));
            int hora = calendar.get(Calendar.HOUR_OF_DAY);
            int minuto = calendar.get(Calendar.MINUTE);

            Scanner s = new Scanner(System.in);
            int [] p = new int [5];
            int [] aux = new int [5]; 
            for (int i=0; i<5;i++) {
                System.out.println("faça seu pedido! as opções de hoje no cardapio são: "
                + "\n 1- X hamburguer de rato "//demora 20 minutos
                + "\n 2- X filé de grilo "//demora 20 minutos
                + "\n 3- X queijo de cobra "//demora 10 minutos
                + "\n 4- X lonbinho de elefante "//demora 40 minutos
                + "\n 5- X vegetariano (a melhor opção ) "//demora 10 minutos
                + "\n 6- sopa de minhoca");//demora 1 hora
                p[i]=s.nextInt();
            }

            merge(p,aux, 0,p.length-1);
            System.out.println(Arrays.toString(p));
        }


        private static void merge(int[] p, int[] aux, int inicio, int fim) {
            if (inicio<fim) {
             int meio=inicio+fim/2;
              merge(p,aux,inicio,meio);
              merge(p,aux,meio+1,fim);
              intercalar(p,aux,inicio,meio,fim);
            }

        }

        private static void intercalar(int[] p, int[] aux, int inicio, int meio, int fim) {
            for(int i=inicio;i<=fim;i++) 
                aux[i]=p[i];
                int k=inicio;
                int j=meio+1;


            for(int i=inicio;i<=fim;i++) {
                if(k>meio) {
                    p[i]=aux[j++];
                }
                if(j>fim){
                    p[i]=aux[k++];
                }
                if(p[i]<aux[j]){
                    p[i]=aux[i++];
                }
                else {
                    p[i]=aux[j++];
                }
            }
        }

}

Here, compiled normally. I hope to have helped!

Browser other questions tagged

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