We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › I'm having some problem with application of java
Page Index Toggle Pages: 1
I'm having some problem with application of java (Read 326 times)
I'm having some problem with application of java
Oct 29th, 2008, 7:10am
 
I have a java program which is to be implemented in processing project for graphic visualisation. The program got executed  successfully in comand prompt. The program needs input values, i can find how to input values in processing platform. If thats not possible, let me know.
can u please guide me in this issue. The java code follows:

import java.io.IOException;
import java.util.*;
import java.lang.reflect.Array;
class RodLength
{
public static void main(String[] args)
{
int n=0;
double l=0;
try
{
n = Integer.parseInt(args[0]);
l = Double.parseDouble(args[1]);
}
catch (Exception e)
{
System.out.println("Format is 'java RodLength n cl'\nWhere n = number of rods\ncl = consistent length");
}
double[] s = new double[n];
double[] s1 = new double[n];
for(int i=0;i<n;i++)
s[i]=0.0;
try
{
System.out.println("Enter " + n + " values for rod length::");
Scanner in = new Scanner(System.in);
for(int i=0;i<n;i++)
{
s[i] = in.nextDouble();
}
in.close();
}
catch (Exception ex)
{
System.out.println(ex);
}
int r = 2;//maximum number of joints
Arrays.sort(s);
int j = 0;
for(int i=0;i<n;i++)
{
if (s[i]==l)
{
s1[j] = s[i];
s[i] = 0;
j++;
}
else if (s[i]>l)
{
s[i] = l - s[i];
s1[j] = l;
j++;
}
}
Arrays.sort(s);
double[] s2 = new double[4];
int i1 = 0;
int i2 = n-1;
int k = 0;
while (i1<=i2)
{
if (s[i1]+s[i2]==l)
{
s2[k] = s[i1];
s2[k+1] = s[i2];
k = k+2;
i1++;
i2--;
}
else if (s[i1]+s[i2]>l)
{
i2--;
}
else if (s[i1]+s[i2]<l)
{
i1++;
}
}
Arrays.sort(s);
//Arrays.sort(s1);
//Arrays.sort(s2);

for(int p=0;p<Array.getLength(s);p++)
System.out.print(s[p] + " ");
System.out.println();
for(int p=0;p<Array.getLength(s1);p++)
System.out.print(s1[p] + " ");
System.out.println();
for(int p=0;p<Array.getLength(s2);p++)
System.out.print(s2[p] + " ");
}
}
Re: I'm having some problem with application of ja
Reply #1 - Oct 29th, 2008, 7:03pm
 
I think you will be interested by the following thread: String and Numerical Input and Handling.
Page Index Toggle Pages: 1