need help

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.

Howdy, Stranger!

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

Categories