Need help with this code. Anyone with knowledge on java please help.
i found some on this forum, but that is also wrong. can anyone give me some help
what is want is to smooth the values in an integer array. If its totally wrong please dont yell

import java.io.*;
import javax.swing.*;

public class arraytest
{	
	public static void main(String args[])
	{	
		String getsize = JOptionPane.showInputDialog(null,"enter a value for the size of the array:","Input",JOptionPane.QUESTION_MESSAGE);
		
		int arraysize = Integer.parseInt(getsize);
		
		
		int[] getsignal = new int [arraysize];
		
		getsignal = getsignal(arraysize);
		
		int[]getsmoothignal = smooth (arraysize.getsignal);
		
		JOptionPane.showMessageDialog(null,showoutput(getsizearray,getsignal,getsmoothsignal)+"complete\n","Output",JOptionPane.INFORMATION_MESSAGE);
		
		System.exit(0);
	}

	
	
	public static int[] getsignal(int s)
	{		
		//declare
		int[] getnumber = new int [s];
		
		
		for(int index = 0; index < s; index++)
		{		
			String getintstring = JOptionPane.showInputDialog(null,"enter value of array:","Input",JOptionPane.QUESTION_MESSAGE);
			
			getnumber[index]=Integer.parseInt(getIntString);
			
			
			while (getnumber[index]<2)
			{		
				JOptionPane.showMessageDialog(null,"Please re-insert your values","Output",JOptionPane.ERROR_MESSAGE);
				
				getIntString = JOptionPane.showInputDialog(null,"Enter values of array:","Input",JOptionPane.QUESTION_MESSAGE);
				
				getnumber[index] = Integer.parseInt(getIntString);
			}
		}

		return getnumber;
	}

	
	public static int[]smooth(int a, int[] signals)
	{
		
		int[]smooth = new int [a];
		
		
		smooth[0]=(signals[0]+signals[1])/2;
		
		
		for (int i = 1; i <= a - 2; i++)
		{
			smooth[i]=(signals[i-1]+signals[i]+signals[i+1])/3;		
		}
		
		int endValue = a - 1;
		smooth[endvalue]=(signals[endvalue-1]+signals[endvalue])/2;
		
		return smooth;
	}
		
	
	public static string showOutput(int a, int[]signal,int[]smooth)
	{
		
		String output = "signal"+" "+smooth ;
		for (int index = 0; index < a; index++)
		{
			output = signal[index]+" "+" " +smooth[index]+"\n";
		}
		return output;
	}
}

What part is "wrong" in your estimation? Wrong is a pretty broad area. Just glancing at the smooth() method it looks like a basic 3 point moving average. Where is the issue?

well ..see i am least gud in java..yet to learn..
there are too many errors which i am nt able to correct...didn understnd hw to bring about the output in JOptionPane..

well ..see i am least gud in java..yet to learn..
there are too many errors which i am nt able to correct...didn understnd hw to bring about the output in JOptionPane..

Get it down to a manageable number of errors. Start commenting things out till everything works. If you get errors before you even get to call the smooth function, comment out the call to the smooth function and the smooth function itself and see if you get fewer. I'd comment out everything but the first line in main first and see if it compiles. If it doesn't, fix it. Then uncomment the second line and compile, see if you get any errors, then the third line, etc. You have to do it in stages. Don't try to debug an entire program full of bugs all at once.

public static string showOutput(int a, int[]signal,int[]smooth)

There is not such thing as a "string". The correct declaration is String with capital S. And most important, java is case sensitive. Meaning that if you want to call the above method you should call it like this: showOutput NOT like this: showoutput. Try to find where you have such a mistake because I think I've seen in other places, and not only for showOutput but other variables as well. You declare them
like: endValue
and I see that you use them
like: smooth[ endvalue ] = ...

Try to correct the above and continue with the others.

And do remember that there is a place for whitespace. int[]variable is NOT good, I think it won't even compile.

This article has been dead for over six months. Start a new discussion instead.