Results 1 to 4 of 4
  1. #1
    yagoob is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default help for my problem please

    hi friends
    sorry for bad english writing
    i take a projects to ecilips and my code had errors in 3 line line 8-11-44 please read my code and help me
    tanks
    Java Code:
    import java.util.*;
    
    public class p33 {
    
    	public static void main(String[] args) {
    
    		Object input;
    		String s= input.next();
    		System.out.println(s);
    		double sum1 = ml32(s);
    		double n = string ml33;
    		String s1 ;
    
    		
    	}
    
    	static double ml33(String s) {
    		int x, b, d;
    		int cs = s.length();
    		int a = 0;
    		for (int c1 = 0; c1 < cs; c1++)
    			if (s.charAt(c1) == '(')
    				a++;
    		int e=0;
    		while (e <= a) {
    			d = indexof(s, ')');
    			int n = 0;
    			for (x = d - 1; x > 0; x--) {
    
    				b = indexof(s, '(');
    				if (b != -1)
    					break;
    			}
    
    			for (int y = d - 1; y > b; y--)
    				n = n * 10 + (s.charAt(y) - '0');
    			String p = "";
    			double ml32;
    			p = "" + ml32;
    			String k1 = Replace(s, p,0);
    			e++;
                
    		}
    retern n;
    
    
    		
    
    	}
    
    	static double ml32(String s) {
    		if (s.charAt(0) >= '0' && s.charAt(0) <= '9')
    			s = '+' + s;
    		int cs = s.length();
    		String a[] = new String[100];
    		int ca = -1;
    		char b[] = new char[100];
    		int cb = 0;
    
    		int i;
    		for (i = 0; i < cs; i++) {
    			if (s.charAt(i) == '+' || s.charAt(i) == '-') {
    				b[cb] = s.charAt(i);
    				cb++;
    				ca++;
    				a[ca] = "";
    			}
    
    			else
    				a[ca] = a[ca] + s.charAt(i);
    
    		}
    		ca++;
    
    		double sum = 0;
    		double sum1 = 0;
    		int d = 0;
    		for (int x = 0; x < ca; x++) {
    			d = indexof(a[x], '.');
    
    			if (d == -1)
    				continue;
    			else {
    				double n = 0;
    				int e = 1;
    
    				for (int f = d + 1; f < a[x].length(); f++) {
    					n = n * 10 + (a[x].charAt(f) - '0');
    					e = e * 10;
    				}
    				n = n / e;
    				int g = 0;
    				for (int f = 0; f < d; f++)
    					g = g * 10 + (a[x].charAt(f) - '0');
    				if (b[x] == '+')
    					sum += n;
    				else
    					sum -= n;
    				a[x] = "" + g;
    			}
    
    		}
    		for (int i1 = 0; i1 < ca; i1++)
    
    		{
    			long n = 0;
    			n = strtolong(a[i1]);
    
    			if (b[i1] == '+')
    				sum += n;
    			else
    				sum -= n;
    		}
    		sum1 = sum1 + (sum / 1.0);
    		return sum1;
    
    	}
    
    	// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    	static long strtolong(String s) {
    		long n = 0;
    		for (int x = 0; x < s.length(); x++)
    			n = n * 10 + (s.charAt(x) - '0');
    		return n;
    	}
    
    	// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    	static int indexof(String s, char c) {
    		int i = -1;
    		for (int x = 0; x < s.length(); x++)
    			if (s.charAt(x) == c)
    				return x;
    		return i;
    
    	}
    
    	static String SubString(String S, int n1, int n2) {
    		if (n1 < 0)
    			n1 = 0;
    		if (n2 < 0)
    			n2 = 0;
    		if (n2 > S.length())
    			n2 = S.length();
    		if (n1 > n2)
    			return "";
    
    		String P = "";
    		for (int a = n1; a <= n2; a++)
    			P = P + S.charAt(a);
    		return P;
    
    	}
    
    	static String Replace(String s1, String s, int d) {
    		String p = "";
    		p = SubString(s, 0, d) + s1 + SubString(s, d + s1.length(), s.length());
    		    return p;
    	}
    
    }

  2. #2
    Daryn is offline Senior Member
    Join Date
    Oct 2012
    Posts
    176
    Rep Power
    2

    Default Re: help for my problem please

    On line 10
    Java Code:
    double sum1 = ml32(s);
    you call function ml32 when it should be ml33
    On line 44
    Java Code:
    retern
    you spelled return wrong
    On line 8 im not quite sure what do you mean when you say Object input on line 7
    With the right know how, anything is possible

  3. #3
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    184
    Rep Power
    0

    Default Re: help for my problem please

    Ok so just looking at your main method here:
    Java Code:
        public static void main(String[] args) {
     
            Object input;
            String s= input.next();
            System.out.println(s);
            double sum1 = ml32(s);
            double n = string ml33;
            String s1 ;
     
             
        }
    The problem with line 4 here:

    You didn't create a scanner! You can't input anything without actually creating a scanner (and importing the scanner). (Unless you're trying to do something completely different and I'm misunderstanding).

    You'd need to add
    Java Code:
    import java.util.Scanner;
    at the very top before your class.

    Then, you'd need to actually create the scanner at the beginning of the main method:
    Java Code:
    Scanner input = new Scanner ( System.in );
    And then to use it to get a string, you'd need to do,
    Java Code:
    String s = input.nextLine();
    So that settles one issue.

    I have no clue what you're trying to do in line 7:
    Java Code:
    double n = string ml33;
    You can't declare a variable to be a double and then try to initialize it to a set of letters. Clarify what you are doing there.

    And it looks like you spelled "return" wrong in line 44.

  4. #4
    yagoob is offline Member
    Join Date
    Jan 2014
    Posts
    4
    Rep Power
    0

    Default Re: help for my problem please

    tankyou for answers friends
    I am a student in the first semester and have problems in solving problems
    This is a restaurant I looked up say thanks.
    this program should write in java eclipse

    Restaurant Information Systems: The program must have the following capabilities:
    1 Ability to add, edit, delete and Simple and Advanced Search All restaurants Members include membership number, name, surname, ID -
    National, contact numbers and addresses of all members within a data file is sorted by membership number

    Java Code:
    import java.io.*;
    import java.util.Scanner;
    import java.util.Scanner;
    
    public class a121211 {
    
    	public static void main(String[] args) throws FileNotFoundException {
    		Scanner input=new Scanner(System.in);
    		int x;
    		System.out.print("enter namber:");
    		String a[]=new String[6];
    		for( x=0;x<6;x++)
    			
    		{	if(x==1)
    				System.out.println("enter name:");
    		if(x==2)
    			System.out.println("enter family:");
    		if(x==3)
    			System.out.println("national code:");
    		if(x==4)
    			System.out.println("tel number ");
    		if(x==5)
    			System.out.println("address ");
    		
    			a[x]=input.next();}
    		File f1=new File("D:\\f.txt");
    		File f3=new File("D:\\f1.txt");
    		PrintWriter outfile=new PrintWriter(f3);
    
    		for(x=0;x<4;x++)
    			outfile.print(a[x]+"    ");
    		Scanner b=new Scanner(f1);
    		while(b.hasNext())
    			{outfile.println();
    			outfile.print(b.nextLine());
    			}
    		     outfile .close();
    		     b.close();
    		     f1.delete();
    		    f3.renameTo(f1);
    
    
    
    			}
    
    		}
    Last edited by yagoob; 01-15-2014 at 01:35 PM.

Similar Threads

  1. Problem with a Simple Histogram Problem
    By kathmandu in forum New To Java
    Replies: 12
    Last Post: 06-25-2013, 01:19 AM
  2. Replies: 0
    Last Post: 11-07-2012, 12:44 PM
  3. Small problem with problem with Java, C++ parse program.
    By dragstang86 in forum New To Java
    Replies: 4
    Last Post: 10-30-2011, 03:43 AM
  4. Replies: 9
    Last Post: 09-21-2010, 04:15 PM
  5. simple line problem / for loop problem
    By helpisontheway in forum New To Java
    Replies: 1
    Last Post: 11-17-2009, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •