Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need help

madkrismadkris Posts: 3Member
Hi,

I have two java codes Main.java and doinput.java, i wanted to have them into a single java file.

[code]import java.io.*;
import java.util.StringTokenizer;

class Main {
public class doinput {

static String s = " ";
static DataInputStream stdin = new DataInputStream(System.in);
static StringTokenizer s_tok = new StringTokenizer(s);

public static int nextint() throws java.io.IOException {
/* Will return the next integer from the Input Stream.
Assumes that at least one more integer
remains in the input stream
*/
int n;

while (s_tok.countTokens() == 0) {
s = stdin.readLine();
s_tok = new StringTokenizer(s);
};
n = Integer.parseInt (s_tok.nextToken());
return n;
};

public static String nextsubstring() throws java.io.IOException{
/* Will return the next substring from the Input Stream.
Assumes that at least one more substring
remains in the input stream
*/
String Str;

while (s_tok.countTokens() == 0) {
s = stdin.readLine();
s_tok = new StringTokenizer(s);
};
Str = s_tok.nextToken();
return Str;
};

}

public static void main (String [] args) throws IOException {
int num, sum, count;
String num_string;
doinput myinput = new doinput();

System.out.println("PERFECTION OUTPUT");

num = myinput.nextint();

while (num != 0) {
// what is it?
if (num != 1)
sum = 1;
else sum = 0;
count = 2;
while (count < num) {
if ((num % count) == 0)
sum = sum + count;
count = count + 1;
}

System.out.print (num + " ");
if (sum < num) System.out.println ("DEFICIENT");
if (sum == num) System.out.println ("PERFECT");
if (sum > num) System.out.println ("ABUNDENT");

num = myinput.nextint();
}
System.out.println("END OF OUTPUT");
}
}[/code]

i got the following errors
[code]Main.java:17: inner classes cannot have static declarations
static string s = " ";
Main.java:18: inner classes cannot have static declarations
static DataInputStream stdin = new DataInputStream(System.in);
Main.java:19: inner classes cannot have static declarations
static StringTokenizer s_ok = new StringTokenizer(s);
Main.java:21: inner classes cannot have static declarations
public static int nextint() throws java.IOException {
Main.java:36: inner classes cannot have static declarations
public static String nextsubstring() throws java.IOException {
Main.java:56: non-static variable this cannot be referenced from a static context
doinput myinput = new doinput(); [/code]

can anyone help me get this to run properply?



Sign In or Register to comment.