954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

program won't run

my program won't even run so i must have missed something drastically but i don't see it....
anyway, Create a class called Factor that has a public method called calculateFactor. The method has two two arguments of type integer and checks whether the smaller of the two integers is a factor of the larger of the two integers. The method will return a factor or a zero. Write a main method which repeatedly reads in a positive integer n (exiting only when n is negative), and displays out the largest proper divisor of n (that is, the largest factor of n that is less than n itself).
This is what i have:

import java.io.*;
import java.util.*;

class Factor{
public int calculateFactor(int n1, int n2){
int factor =0;
if(factor==0)
	return 0;
else {
return factor;
}//end public
}//end class

public class lab7_1 {
public void main(String[]args){
System.out.print("input an integer number:");
Factor f= new Factor();
int n;
n=0;
int i;
i=2;
double value;
value=f.calculateFactor(i,n);
while(i<=n)
System.out.print("largest divisor");
}

}
}
custurd12
Newbie Poster
13 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 
public static void main (String args[])
{
// code here
}


You forgot the static keyword.

VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
 
my program won't even run so i must have missed something drastically but i don't see it....

Excellent analysis of the problem, also let me congratulate you on the wonderful code alignment technique you have pioneered.
Also do not directly copy paste your assignment.

Here are a few pointers you need to look into while and do while loops in Java - Look here .
Reading an Integer from Console in Java
Sun Java Code Conventions , no need to read the whole document, just go through the basic parts related to code indentation, variable naming etc.
And Vernon already has pointed out the "main" part

stephen84s
Nearly a Posting Virtuoso
1,443 posts since Jul 2007
Reputation Points: 668
Solved Threads: 154
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You