Exercicis de Mètodes Estàtics en Java: Solucions Resoltes
Exercicis de Mètodes Estàtics: Respostes
1. Funció per calcular f(x,y) = 2x + 3y²
Programa que utilitza una funció per calcular f(x,y) = 2x + 3y² en un domini real.
import javax.swing.JOptionPane;...
public class Funcao {
static String xs, ys;
static int x, y;
public static int calcula(int x, int y) {
return 2 * x + ((3 * y) * (3 * y));
}
public static void le() {
xs = JOptionPane.showInputDialog("Informe o valor de x");
ys = JOptionPane.showInputDialog("Informe o valor de y");
}
public static void converte(String a, String b) {
x = Integer.parseInt(a);
y = Integer.parseInt(b);
}
public static void exibe(int a, int b) {
JOptionPane.showMessageDialog(null, "f(x, y) = " + calcula(a, b));
}
public static void main(String args[]) {
le();
converte(xs, ys);
exibe(x,