Two questions!

• 11-09-2012, 12:11 AM
eranmc
Two questions!
Hello you guys, I'm new in here.

1. I need to program a program which receive a number from a user and finds the highest number of prime numbers below a given number. For example 11 is the highest number which is smaller than 13. Have no clue how :(wait):

2. I get 4 integer numbers, the first 2 are coefficient and the others are 2 coordinates, I need to find if the given coordinates point is below, on or above y=ax+b, the output should be like that: (x,y) is {below, on, above} the line y=ax+b
for example the output for: 1, 0, 1, 2 (1,2) is above the line y=1x+0

This is my FullOfErrors code, how you'll help me:

public class Ex2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt(); // Get coefficient a from user
int b = sc.nextInt(); // Get coefficient b from user
int x = sc.nextInt(); // Get coordinates x from user
int y = sc.nextInt(); // Get coordinates y from user
if (y == a * x + b){
System.out.println("("+x+","+y+")" is on the line y=" a+"x+"b);
else{
if (y > a * x + b){
System.out.println("("+x+","+y+")" is above the line y=" a+"x+"b);
}
else{
if (y < a * x + b){
System.out.println("("+x+","+y+")" is under the line y=" a+"x+"b);
}
}
}

Thank You!
• 11-09-2012, 03:54 PM
Kagiso
Re: Two questions!
friend your code is almost fine the only things you got wrong is the placement of your ""signs, try looking at your code again!!!

jst to make this code look neater I would assign the value of a*x + b to an int variable and remove the curly braces on the if...else
• 11-09-2012, 04:35 PM
eranmc
Re: Two questions!
Thanx!