Java

Moderators: zibadian
Number of threads: 7836
Number of posts: 18235

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
need help Posted by madkris on 14 Mar 2009 at 11:42 PM
Hi,

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

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");
	}
}


i got the following errors
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();                       


can anyone help me get this to run properply?






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.