1. Member Join Date
Nov 2012
Posts
2
Rep Power
0 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 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!
Last edited by eranmc; 11-08-2012 at 11:23 PM. Reason: English  Reply With Quote

2. Member Join Date
Nov 2012
Location
Johannesburg, South Africa
Posts
92
Rep Power
0 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  Reply With Quote

3. Member Join Date
Nov 2012
Posts
2
Rep Power
0 Re: Two questions!

Thanx!  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•