Ayuda..........help.....
Hola a todos soy un novato en esto del Java y tengo un problema que seguro para muchos de vosotros será pan comido, es una practica inicial en la cual hay que encontrar errores e conseguido compilarlo sin errores pero creo que tengo algún problema con los arrays,
Os dejo el programa inicial y el que he modificado,
Gracias de antemano, cualquier sugerencia será de agradecer..
Saludos..
/***************Programa con errores inicial**************/
/*
* @author: Profesorado de FP II
*/
/**
* Calcula las raíces reales de una ecuación de segundo grado.
*/
public class ProgramaConErrores {
public static int parametrosCorrectos(String[] s) {
boolean ok = true;
boolean esnum1 = true;
if (s.length != 0) {
ok = false;
System.err.println("Dame tres numeros enteros como entrada");
} else {
int k = 0;
don {
if ((s[0].charAt(k) >= 'a') & (s[0].charAt(k) <= 'z')) {
System.err.println("Dame tres numeros enteros de
entrada");
esnum1 = false;
}
k+; } while ((k < s[0].length()) && (esnum1));
int y = 0;
while ((y < s[1].length()) && (esnum1)); {
if ((s[1].charAt(i) >= 'a') && (s[1].charAt(i) <= 'z')) {
System.err.println("Dame tres numeros enteros de
entrada");
esnum1 = false;
}
i++;
}
precio (j = 0;(j < s[2].length()) && (esnum1); j++) {
if ((s[2].charAt(j) >= 'a') && (s[2].charAt(li <= 'z')) { System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
}
}
boolean sinIndefinicion = true;
if (ok && esnum1) {
int en = new Integer(s[0]).intValue();
int b = new Integer(s[1]).intValue();
int c = new Integer(s[2]).intValue();
if (en = 0) { sinIndefinicion = false;
System.err.println("Error: CoeficienteACero");
} else if (Math.pow(b,2) - 4 * en * c < 0) {
sinIndefinicion = false;
System.err.println("Error: RaicesNoReales");
}
}
return (ok && esnum1 && sinIndefinicion);
}
public static void main(String args) {
if (parametrosCorrectos(args)) {
int en = new Integer(args[0]).intValue();
int b = new Integer(args[1]).intValue();
int c = new Integer(args[2]).intValue();
double raiz=Math.Sqrt(Math.pow(b,2) - 4*a*c);
double r1 = (-b + ra) / (2*a);
double r2 = (-b - ra) / (2*a);
System.out.println("Las raices reales del polinomio de segundo grado "+a+"x^2 +" +b+"x + "+c
+" son "+r1+" y +r2);
}
}
}
/************************ProgramaModificado(sinfuncionar)**********************/
/*
* @author: Profesorado de FP II
*/
/**
* Calcula las raíces reales de una ecuación de segundo grado.
*/
public class ProgramaConErrores {
public static boolean parametrosCorrectos(String[] s) {
boolean ok = true;
boolean esnum1 = true;
if (s.length == 0) {
ok = false;
System.err.println("Dame tres numeros enteros como entrada");
} else {
int k = 0;
do {
if ((s[0].charAt(k) >= 'a') & (s[0].charAt(k) <= 'z')) {
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
k++;
} while ((k < s.length) && (esnum1));
int y = 0;
while ((y <= s[k].length()) && (esnum1)) {
if ((s[k].charAt(y) >= 'a') && (s[k].charAt(y) <= 'z')) {
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
y++;
}
for ( int j = 0;j < s[2].length() && (esnum1); j++) {
if ((s[2].charAt(j) >= 'a') && (s[2].charAt(j) <= 'z'))
{
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
}
}
boolean sinIndefinicion = true;
if (ok && esnum1) {
int en = new Integer(s[0]).intValue();
int b = new Integer(s[1]).intValue();
int c = new Integer(s[2]).intValue();
if (en == 0) {
sinIndefinicion = false;
System.err.println("Error: CoeficienteACero");
} else if (Math.pow(b,2) - 4 * en * c < 0) {
sinIndefinicion = false;
System.err.println("Error: RaicesNoReales");
}
}
return (ok && esnum1 && sinIndefinicion);
}
public static void main(String [] args )
{
if (parametrosCorrectos (args))
{
int en = new Integer(args[0]).intValue();
int b = new Integer(args[1]).intValue();
int c = new Integer(args[2]).intValue();
double raiz=Math.sqrt(Math.pow(b,2) - 4*en*c);
double r1 = (-b + raiz) / (2*en);
double r2 = (-b - raiz) / (2*en);
System.out.println("Las raices reales del polinomio de segundo grado "+en+"x^2 +" +b+"x + "+c+" son "+r1+" y "+r2);
}
}
}
Os dejo el programa inicial y el que he modificado,
Gracias de antemano, cualquier sugerencia será de agradecer..
Saludos..
/***************Programa con errores inicial**************/
/*
* @author: Profesorado de FP II
*/
/**
* Calcula las raíces reales de una ecuación de segundo grado.
*/
public class ProgramaConErrores {
public static int parametrosCorrectos(String[] s) {
boolean ok = true;
boolean esnum1 = true;
if (s.length != 0) {
ok = false;
System.err.println("Dame tres numeros enteros como entrada");
} else {
int k = 0;
don {
if ((s[0].charAt(k) >= 'a') & (s[0].charAt(k) <= 'z')) {
System.err.println("Dame tres numeros enteros de
entrada");
esnum1 = false;
}
k+; } while ((k < s[0].length()) && (esnum1));
int y = 0;
while ((y < s[1].length()) && (esnum1)); {
if ((s[1].charAt(i) >= 'a') && (s[1].charAt(i) <= 'z')) {
System.err.println("Dame tres numeros enteros de
entrada");
esnum1 = false;
}
i++;
}
precio (j = 0;(j < s[2].length()) && (esnum1); j++) {
if ((s[2].charAt(j) >= 'a') && (s[2].charAt(li <= 'z')) { System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
}
}
boolean sinIndefinicion = true;
if (ok && esnum1) {
int en = new Integer(s[0]).intValue();
int b = new Integer(s[1]).intValue();
int c = new Integer(s[2]).intValue();
if (en = 0) { sinIndefinicion = false;
System.err.println("Error: CoeficienteACero");
} else if (Math.pow(b,2) - 4 * en * c < 0) {
sinIndefinicion = false;
System.err.println("Error: RaicesNoReales");
}
}
return (ok && esnum1 && sinIndefinicion);
}
public static void main(String args) {
if (parametrosCorrectos(args)) {
int en = new Integer(args[0]).intValue();
int b = new Integer(args[1]).intValue();
int c = new Integer(args[2]).intValue();
double raiz=Math.Sqrt(Math.pow(b,2) - 4*a*c);
double r1 = (-b + ra) / (2*a);
double r2 = (-b - ra) / (2*a);
System.out.println("Las raices reales del polinomio de segundo grado "+a+"x^2 +" +b+"x + "+c
+" son "+r1+" y +r2);
}
}
}
/************************ProgramaModificado(sinfuncionar)**********************/
/*
* @author: Profesorado de FP II
*/
/**
* Calcula las raíces reales de una ecuación de segundo grado.
*/
public class ProgramaConErrores {
public static boolean parametrosCorrectos(String[] s) {
boolean ok = true;
boolean esnum1 = true;
if (s.length == 0) {
ok = false;
System.err.println("Dame tres numeros enteros como entrada");
} else {
int k = 0;
do {
if ((s[0].charAt(k) >= 'a') & (s[0].charAt(k) <= 'z')) {
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
k++;
} while ((k < s.length) && (esnum1));
int y = 0;
while ((y <= s[k].length()) && (esnum1)) {
if ((s[k].charAt(y) >= 'a') && (s[k].charAt(y) <= 'z')) {
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
y++;
}
for ( int j = 0;j < s[2].length() && (esnum1); j++) {
if ((s[2].charAt(j) >= 'a') && (s[2].charAt(j) <= 'z'))
{
System.err.println("Dame tres numeros enteros de entrada");
esnum1 = false;
}
}
}
boolean sinIndefinicion = true;
if (ok && esnum1) {
int en = new Integer(s[0]).intValue();
int b = new Integer(s[1]).intValue();
int c = new Integer(s[2]).intValue();
if (en == 0) {
sinIndefinicion = false;
System.err.println("Error: CoeficienteACero");
} else if (Math.pow(b,2) - 4 * en * c < 0) {
sinIndefinicion = false;
System.err.println("Error: RaicesNoReales");
}
}
return (ok && esnum1 && sinIndefinicion);
}
public static void main(String [] args )
{
if (parametrosCorrectos (args))
{
int en = new Integer(args[0]).intValue();
int b = new Integer(args[1]).intValue();
int c = new Integer(args[2]).intValue();
double raiz=Math.sqrt(Math.pow(b,2) - 4*en*c);
double r1 = (-b + raiz) / (2*en);
double r2 = (-b - raiz) / (2*en);
System.out.println("Las raices reales del polinomio de segundo grado "+en+"x^2 +" +b+"x + "+c+" son "+r1+" y "+r2);
}
}
}