Maksymalna liczba z 3 wprowadzanych tworzenie metody.

0

Witam ponownie

Albo mi juz totalnie glowa zardzewiala albo nie wiem o co chodzi.
Staram zrobic metode ktora bedzie zliczala maxymalna liczbe z 3 wprowadzonych

probowalem tak

public int maximum (int x, int y, int z)
{
    return Math.max(Math.max (z(x,y));
}

nie dziala

Pozniej tak


public int maximum (int x, int y, int z)
{
if (x>y)
    return x;
    else
    return y;
if (x>z)
    return x;
    else
    return z;
if (y>z)
    return y;
    else
    return z;
}

nie dziala unreachable statement if (y>z){

Moglby ktos pomoc

import java.applet.Applet;
import java.awt.event.*;
import java.awt.*;

public class Maximum extends Applet implements ActionListener
{
    //declare labels
    Label label1, label2,label3, resultlabel;

    //declare textfields
    TextField number1, number2,number3, resultnumber;

    //declare variables
    int num1, num2,num3, max;

public void init()
    {
        //create labels
        label1 = new Label("Enter first Integer:");
        label2 = new Label("Enter second Integer:");
        label3 = new Label("Enter third Integer:");
        resultlabel = new Label("Largest Value is: ");

        //create textfields
        number1 = new TextField(10);
        number2 = new TextField(10);
        number3 = new TextField(10);
        number3.addActionListener(this);

        resultnumber = new TextField(10);
        resultnumber.setEditable(false);

        //add labels and textfields to applet
        add(label1);
        add(number1);

        add(label2);
        add(number2);

        add(label3);
        add(number3);

        add(resultlabel);
        add(resultnumber);
    }

public int maximum (int x, int y, int z)
{
return Math.max(x, Math.max(y, z));
}

public void actionPerformed(ActionEvent e)
    {
    num1 = Integer.parseInt(number1.getText());
    num2 = Integer.parseInt(number2.getText());
    num3 = Integer.parseInt(number2.getText());
    //this code calls method maximum, passes two parameters num1 and num2
    //the result returned is stored in the max variable

    max = maximum(num1, num2, num3);

    //convert max to a string
    //display the result in the resultnumber textfield

    resultnumber.setText(Integer.toString(max));
    }
}
1

Math.max(x, Math.max(y, z))

1
Math.max(Math.max(x, y), z)

Przecież to wyrażenie nie ma sensu

z(x, y)
0
katelx napisał(a):

Math.max(x, Math.max(y, z))

niestety nadal nie dziala

0

pomoze ktos ?

1
num3 = Integer.parseInt(number3.getText());

1 użytkowników online, w tym zalogowanych: 0, gości: 1, botów: 0