|
How to round this 106.19999999999999 number like 106.20 by using java script?
|
|
|
|
|
udch wrote: java script
That's not Java
Anyway you could just do Math.round[^](106.19999999999999 * 100) / 100
|
|
|
|
|
Hi all,
I want to animate 2D images, specially face;
My scenario is i should draw contours of face around the image, on next key frame i should change the shapes of contour. When i animate i get the face in the image should animate accordingly.
It is something like morphing, but in morphing we have 2 images. In my scenario i have one image.
If i conclude i want some thing like this http://www.youtube.com/watch?v=ed_HAJGJfeQ[^]
I want to do it programatically, to create Talking Pictures.
I know you all guys are specialist into such kind of things. Please guide me how to full fill my scenario.
Thanks in advance.
Please do it as early as possible.
Nazar Hussain
|
|
|
|
|
Identical question on the C# forum, could the two be related?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I posted on two forums, so if any guru of Java or C# could help me.
|
|
|
|
|
Is the question Java or C#? If one or other, then in belongs in just the one.
Cross posts are very distracting, as you can see, a lot of pouple go to multiple forums and seeing the same post is just not accepted.
Please, only post a question in the one, most relevant, place. if you are not sure you are posting in the righ forum, say so up front and you will be directed, politely, to the correct forum.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Ok. Thanks for your guidance. I will never post same question on multiple forums.
Regards
Nazar
|
|
|
|
|
hi, im new to java.
regarding string array, is there a way to do string index.??
example:
String[] arr = null;
arr["name"]="myname";
arr["age"]="myage";
arr["gender"]="mygender";
The reason to my question is because im creating a class user. the variables will be private. i would need to get and set these variables, therefore creating a set of get() and set() function for each variable. If i can do the above method, i would simply need one set of get() and set() function.
hope thats not too confusing.
Thanks.
modified on Saturday, July 25, 2009 7:12 AM
|
|
|
|
|
Check this code, if convienent:
class Indexer{
static int returnIndex(String inp)
{
int ret_val=-1;
if(inp.equals("name")) ret_val=0;
if(inp.equals("age")) ret_val=1;
if(inp.equals("gender")) ret_val=2;
return ret_val;
}
public static void main(String [] args){
String[] arr = null;
arr[returnIndex("name")]="myname";
arr[returnIndex("age")]="myage";
arr[returnIndex("gender")]="mygender";
}
}
Kujtim
|
|
|
|
|
How will the keys be generic if he doesn't know the key strings to begin with?
Personaly I wold use a swicth , instead of multiple if statements, in returnIndex .
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
You will need to use Map[^]. Explanation[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Hello Pals,
I've written a program which declares an array of size 3, initializes its elements and prints the elements. The program is as follows:
package Demo;
import java.io*;
public class A{
public A(){}
public static void main(String args[])throws IOException{
int[] anArray=new int[3];
anArray[0]=10;
anArray[1]=20;
anArray[2]=30;
System.out.println("Array[0] index now contains: "+anArray[0]);
System.out.println("Array[1] index now contains: "+anArray[1]);
System.out.println("Array[2] index now contains: "+anArray[2]);
}
}
Now, suppose the array size is very long say 100! Then, will I have to keep on typing System.out.println(anArray[0]......anArray[99]);???
Wont that be huge? I C#.NET, we have the for-each loop construct to print all the elements in an array. Similarly, can I implement the for-each loop here? I did try, but I get Error as this: missing .class
Can anyone help me with an effecient way of printing elements in Java?
Help will be greatly appreciated,
Rajdeep
I calculate my days on earth..... approximately 55 years remaining for me to expire
|
|
|
|
|
I take it that you still can't use google. Help[^].
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
You really don't have a clue, do you?
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
|
Is there a way to create and use a ruby object inside java code?
Thanks
|
|
|
|
|
|
Hello,
this is a simple question I think. I am trying to get the array of bytes as a reference from method, although in the method in creates the array, outside returns the original initialized with null. How to get it from routine, but as parameter since routine returns boolean. Maybe routine should return class containing the array and boolean variable.
This is the code:
public class PassingRefs{
static boolean varbyteobject(byte [] obj)
{
System.out.println("---inside routine---");
int rndlen=(int)(Math.round(Math.random()*50)+1);
obj=new byte[rndlen];
System.out.println(obj.length);
return true;
}
public static void main(String [] args){
byte [] inpobj=null;
varbyteobject(inpobj);
System.out.println("---out from routine---");
System.out.println(inpobj.length);
}
}
and this is what I get after execution:
---inside routine---
29
---out from routine---
Exception in thread "main" java.lang.NullPointerException
at PassingRefs.main(PassingRefs.java:18)
Kujtim
|
|
|
|
|
In Java, all method parameters are passed by value, not by reference.
In other words, when you call varbyteobject in your code, it does not pass the reference to the original byte array. It passes a copy of the reference to the byte array. So, this line of code:
obj=new byte[rndlen];
has no effect on the original reference to the byte array in the calling main method since you are updating the copy, not the original.
It is explained in more detail in this article:
http://www.javaworld.com/javaworld/javaqa/2000-05/03-qa-0526-pass.html[^]
You can just return the new byte array from your method. Why do you want to return a boolean?
|
|
|
|
|
SPIRANCA wrote:
static boolean varbyteobject(byte [] obj)
{
System.out.println("---inside routine---");
int rndlen=(int)(Math.round(Math.random()*50)+1);
obj=new byte[rndlen];
System.out.println(obj.length);
return true;
}
varbyteobject(inpobj);
Why do you need to return a boolean ? Why not just pass the byte[] back?
Personally I would return an intialised byte[] if it was true and null if it was false .
static byte[] varbyteobject(byte[] obj)
{
...
return obj;
}
if ((inpobj = varbyteobject(inpobj)) != null)
System.out.println(inpobj.length);
else
System.out.println("Array not initialised.");
If at first you don't succeed, you're not Chuck Norris.
|
|
|
|
|
Possible solution would be to return a struct-class(since Java doesn't supports structs), so that it contains the byte array and the boolean variable(which tells about success or failure). Although we could check the success or failure from the byte array-some of the byte contain that info.
Thanks anyway,
Kujtim
|
|
|
|
|
Success or failure in what sense? Looking at the example code you have posted there is very little that can go wrong.
The convention in Java is that success of an operation like this is assumed and you can expect a byte array to be returned: if anything goes wrong and the operation cannot be completed successfully, an exception is thrown. This may be a checked or an unchecked exception. There is a lot of debate over which of these is better, and I have no desire to open that debate up here (we'll be here forever while people argue backwards and forwards). Lets just say that if the operation fails, an exception is thrown and the type of exception tells you what went wrong. The calling method then catches the exception and responds accordingly.
In other words, your method returns an intialised byte array. If the initialisation of the byte array fails, throw an exception indicating why it failed. I can't tell you what exception would be best because I don't know what you expect to go wrong from the example code you posted.
You certainly could make it work by returning a class containing the byte array and a success/failure flag but this is not the preferred way of doing it in Java.
|
|
|
|
|
This very very simplified part of the large project I am developing. It will manage (register, unregister, list, ...) clients to listen/write at serial(COM) and TCP/IP. So the byte array is actually stream that commes(input arg) and goes(returned by function) by the so called "bridge" I am developing. Bytes of the stream contain the info from / to the requester.
Hope this is more clear.
Kujtim
|
|
|
|
|
In that case, I would definitely use an exception to indicate failure. Personally I would use a checked exception in this case (puts on tin hat and runs for cover from the "I hate checked exceptions" brigade) but YMMV.
Returning a success indicator is a very C way of doing things. Using a class as an equivalent of a struct to hold the byte array and a yes/no success flag is the result of trying to force C coding practices onto Java, which is why it feels clumsy and inelegant.
|
|
|
|
|
The remote user issues registration request from the GUI. For that request we build a stream which contains all the details. It is executed on the host module, if succeeds it receives the answer upon success, if not it receives failure message stream. We defined dedicated PROTOCOL for this.
Any failure is catched and handled by try/catch internally. But the remote objects needs to communicate between, thus the protocol between them.
Kujtim
modified on Monday, July 27, 2009 9:42 AM
|
|
|
|