Java Class EASY Assignment
My problem is that I cannot get the method printMultiples to print. If I try to put a print statement in main it just says cannot find symbol, so I put the method in main and it works, but I have to use a method in my assignment. The program assigns N and a multiple and gets input from the user. The method printMultiples takes the variable n the user input and gets the first 6 multiples. My real question is how do i get n incorporated with printMultiples and get printMultiples to print?
Code :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package factorial;
/**
*
* @author student
*/
import java.util.Scanner;
public class Factorial {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int n;
Scanner reader = new Scanner (System.in);
System.out.println("What Number?");
n = reader.nextInt ();
System.out.println(printMultiples);
}
public static void printMultiples (int n, int result) {
int i = 1;
while (i <=6) {
System.out.print(n*i + " ");
i = i + 1;
}
System.out.println("");
}
}
Re: Java Class EASY Assignment
Re: Java Class EASY Assignment
There are a few options you can do to fix this problem. Since you're using a static method you can just literally call the method by typing in the name:
Code :
int n;
Scanner reader = new Scanner (System.in);
System.out.println("What Number?");
n = reader.nextInt ();
printMultiples(100,10);
}
public static void printMultiples (int n, int result) {
int i = 1;
while (i <=6) {
System.out.print(n*i + " ");
i = i + 1;
}
System.out.println("");
}
}
if you've remove the word static in your method, then you would have to call the method by making an object. Not sure if you want more details on that at this point, but I edited your code and I hope that helps.
Re: Java Class EASY Assignment
I just put random numbers in there, because I didn't really know what arguments you wanted to pass into your static method.
Re: Java Class EASY Assignment
printMultiples(n); //in the main....I think