Monday, May 24, 2010

Jave Help...pleaaaaaase?

I'm studying for a test, and am looking for two syntax and one runtime errors in this little program:





import java.util.Scanner;


public class MaxMinRatio {


public static void main( String [] args ) {


Scanner in = new Scanner(System.in);


a = in.nextInt();


b = in.nextInt();


c = in.nextInt();


int min;


int max;


max = min = a;


if b %26gt; max { max = b; }


if c %26gt; max { max = c; }


if min %26gt; b || min %26gt; c {


min = b;


} else min = c;


System.out.println("ratio = " + max / min);


}


}





I have another, smaller program to compare it with and I have found one syntax but I've been looking at it for awhile and can't see anymore....any help would be great.

Jave Help...pleaaaaaase?
I see three syntax errors: the expression for IF must be in parentheses.





The runtime error is going to be: Can not convert "int" to "string"





Note that you are going to get an integer result from "max / min" - and also that you did not check for possible divide by zero errors. So, if max is 3 and min is 2, your result is going to be 1, not 1.5.





I think there is also a logic error there... the min isn't set correctly. You start by setting it to the value of "a" - then if a is greater than either b or c, you set the min to be "b", but if it's less than both of those, you set the min to "c"? What happens if they are equal? How can "c" ever be the min?
Reply:always place a bracket "(" at the "if" statement. I dont see any other problems. Why not run the program and tell us the errors you get?
Reply:Here are two errors





Always conditions should be in brackets.Pls keep all your if condition in paranthesis





if(b%26gt;max)


if(c%26gt;max)


if(min%26gt;b||min%26gt;c)





Secondly a,b,c are not delcared





So after in main fucntion delare a,b,c as int








Run time error because your not closing the file at the end of program


No comments:

Post a Comment