I'm trying to use a method to calculate y for all values between 1 and x of a given x for straight lines.
I want the values for y to be placed in an array and returned to the main method. When I run my program all values in the array are 0; where have I gone wrong?
Thanks!
import java.util.Scanner;
public class HelloWorld {
public static void main(String [] args)
{
int n=0;
int k=0;
int m=0;
Scanner in = new Scanner(System.in);
System.out.println("Value of x: ");
n = in.nextInt();
int line[] = new int [n];
System.out.println("value of k: ");
k = in.nextInt();
System.out.println("Value of m: ");
m = in.nextInt();
calcLine(n,k,m);
for(int i = 0; i < line.length; i++){
System.out.println(line[i]);
}
}
public static int[] calcLine(int n, int k, int m)
{
int[] line = new int[n];
for (int i=0; i<line.length;i++){
line[i] = (int) (k * i + m);
}
return line;
}
}