|
do you know something called "javadoc" ? just kidding
in java (and in C++), the type double handles such precision.
then, you just have to call the correct functions, which you'll find reference in the online documentation.
in C++, just #include <cmath> and use sin() and cos() like this.
in Java, just call Math.sin() and Math.cos()...
|
|
|
|
|
Hello
i'm just downloaded apache tomcat 6.0 but i can't set it to netbeans 6.0.1 please help me...
|
|
|
|
|
I have this problem too, I don't know how I should use Apache Tomcat 6.0 in my NetBeans, is there anyone that can help?
While (true) { Human.isLearnable = true; }
|
|
|
|
|
I just finished writing this program, what it does is takes your name and assigns each letter a number and adds them up,
ie. Tanner would give you 27
The program then checks to see if the number is one or two digits, which in this case it is two (2 and 7)
It then adds those two digits together. Comments explain everything
What I would like input on is if anyone could give me a couple pointers on how to optimize my code, make it faster or take away some of the writing to reduce it's length
import javax.swing.*;
public class bruce_tanner_A2Q2
{
public static void main (String [] args)
{
int firstNameTotal = 0;
int secondNameTotal, thirdNameTotal;
int currentLetter;
String input = JOptionPane.showInputDialog("Numerology Calculator -\nEnter a Name");
int inputLength = input.length();
for(int i = 0;i < inputLength;i++)
{
currentLetter = (int)input.charAt(i) % 60;
if (currentLetter == 5 || currentLetter == 14 || currentLetter == 23
|| currentLetter == 37 || currentLetter == 46 || currentLetter == 55)
{
firstNameTotal++;
}
else if (currentLetter == 6 || currentLetter == 15 || currentLetter == 24
|| currentLetter == 38 || currentLetter == 47 || currentLetter == 56)
{
firstNameTotal = firstNameTotal + 2;
}
else if (currentLetter == 7 || currentLetter == 16 || currentLetter == 25
|| currentLetter == 39 || currentLetter == 48 || currentLetter == 57)
{
firstNameTotal = firstNameTotal + 3;
}
else if (currentLetter == 8 || currentLetter == 17 || currentLetter == 26
|| currentLetter == 40 || currentLetter == 49 || currentLetter == 58)
{
firstNameTotal = firstNameTotal + 4;
}
else if (currentLetter == 9 || currentLetter == 18 || currentLetter == 27
|| currentLetter == 41 || currentLetter == 50 || currentLetter == 59)
{
firstNameTotal = firstNameTotal + 5;
}
else if (currentLetter == 10 || currentLetter == 19 || currentLetter == 28
|| currentLetter == 42 || currentLetter == 51 || currentLetter == 0)
{
firstNameTotal = firstNameTotal + 6;
}
else if (currentLetter == 11 || currentLetter == 20 || currentLetter == 29
|| currentLetter == 43 || currentLetter == 52 || currentLetter == 1)
{
firstNameTotal = firstNameTotal + 7;
}
else if (currentLetter == 12 || currentLetter == 21 || currentLetter == 30
|| currentLetter == 44 || currentLetter == 53 || currentLetter == 2)
{
firstNameTotal = firstNameTotal + 8;
}
else if (currentLetter == 13 || currentLetter == 22 || currentLetter == 45
|| currentLetter == 54)
{
firstNameTotal = firstNameTotal + 9;
}
}
secondNameTotal = ((firstNameTotal % 10) + (firstNameTotal - (firstNameTotal % 10)) / 10);
thirdNameTotal = ((secondNameTotal % 10) + (secondNameTotal - (secondNameTotal % 10)) / 10);
if(thirdNameTotal == 1)
System.out.println(input + " (1) is ambitious, independent, and self-sufficient");
if(thirdNameTotal == 2)
System.out.println(input + " (2) is supportive, diplomatic, and analytical");
if(thirdNameTotal == 3)
System.out.println(input + " (3) is enthusiastic, optimistic, and fun-loving");
if(thirdNameTotal == 4)
System.out.println(input + " (4) is practical, traditional, and serious");
if(thirdNameTotal == 5)
System.out.println(input + " (5) is adventurous, mercurial, and sensual");
if(thirdNameTotal == 6)
System.out.println(input + " (6) is responsible, careful, and domestic");
if(thirdNameTotal == 7)
System.out.println(input + " (7) is spiritual, eccentric, and a bit of a loner");
if(thirdNameTotal == 8)
System.out.println(input + " (8) is money-oriented, decisive, and stern");
if(thirdNameTotal == 9)
System.out.println(input + " (9) is multi-talented, compassionate, and global");
}
}
|
|
|
|
|
<font color="blue">for</font> (int i = 0;i < inputLength; i++) {
currentLetter = (<font color="blue">int</font>)input.charAt(i) % 60; <font color="green">
currentLetter = input[i]; <font color="green">
<font color="blue">switch</font> (currentLetter) {
<font color="blue">case</font> 'A': <font color="blue">case</font> 'J': <font color="blue">case</font> 'S':
firstNameTotal += 1;
<font color="blue">break</font>;
<font color="blue">case</font> 'B': <font color="blue">case</font> 'K': <font color="blue">case</font> 'T':
firstNameTotal += 2;
<font color="blue">break</font>;
<font color="green">
}
|
|
|
|
|
Oh dear.. cases totally slipped my mind. Also, I never knew that you could do something like
currentLetter = input[i] . I'm assuming that that will access the String as a character array and return the letter at position i?
|
|
|
|
|
TannerB wrote: I'm assuming that that will access the String as a character array and return the letter at position i?
yup. the [] operator gets the character at position passed in parameter (0-based).
also, a thing I shown in my sample, which i'm not sure you noticed, is using the characters literals instead of their ascii code... this is very handy when you come later and read back your code
|
|
|
|
|
Hello everybody,
I would implement it like this to avoid if or switch statements :
int incrementAmount;
for(int i = 0;i < inputLength;i++){
currentLetter = input.charAt(i);
incrementAmount = (Character.toUpperCase(currentLetter)-'A')%9+1;
firstNameTotal += incrementAmount;
}
Also we can replace :
incrementAmount = (Character.toUpperCase(currentLetter)-'A')%9+1;
By :
incrementAmount = (Character.toUpperCase(currentLetter)-'A')%('J'-'A')+1;
just to be more readable, that means "restart counting after the letter 'J'", which is better than "restart counting after the 9th letter".
I also just noticed that you don't manage the case where thirdNameTotal is equal to 0.
|
|
|
|
|
yup, that's a pretty smart implementation... i didn't took too much time to think on a better optimization, but yours is good
|
|
|
|
|
i have make an appliction on j2me and use digestmesage from java .securtiy but on cldc 1.1 the java.securty not supported
ihad import that
import java.security.MessageDigest;(not supported on cldc1.1 )
and i was import it to use this code
MessageDigest md2 = MessageDigest.getInstance("MD5");
//[CMPE 295B] Following code group added
md2.update(abyPassword,0,abyPassword.length);
md2.update(abySalt,0,abySalt.length);
md2.update(abyPassword,0,abyPassword.length);
byte[] abyFinal = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };//[CMPE 295B]
md2.digest(abyFinal,0,16); //[CMPE 295B]
pleas if any body now how to use the md5 algrothim on j2me cldc 1.1
|
|
|
|
|
I would like to know how to debug MSJVM in Eclipse. I can see Java console of MSJVM but I can't debug my code. Please let me know if you can do it. Thanks!
|
|
|
|
|
you can't if you don't have the source code...
otherwise, set a breakpoint, and start your program with 'debug as...' > 'Java Application'
|
|
|
|
|
Sure. I have a source code. I can debug with JRE. But I can't debug with MSJVM.
|
|
|
|
|
My application is an applet. So, I have to add parameter into JRE. When I run the debug, I see message below:
Failed to connect to remote VM. Connection refused.
Connection refused: connect
Please advise me in this case. Thanks!
|
|
|
|
|
Hi everyone,
i'm working on a project and i need to draw a graph (not a chart, a network).
I think there are some classes or library to do that but i didn't find anything.
Can someone help me? Articles, links...all welcome.
Thanks in advance,
Enrico
Program your life ^^
|
|
|
|
|
|
thanks you were very helpful!
Program your life ^^
|
|
|
|
|
I have a question (or more an impulse for discussion) regarding an implementation of Mergesort with a generic list.
How is a list (let's say an ArrayList) object stored in the memory? How are the list's values stored? I would assume that each list item is a pointer to a value stored in memory, since duplicate objects are possible. How much space is this pointer using in memory?
If I stay with my Mergesort example:
I have a list of n integer values, which means n values of 16 bit stored in the memory, along with n pointers + the "overhead" for the list.
If i split the list in the first step, i have the same integer values in the memory, but now 2n pointers + the "overhead" of 3 lists...
So for implementing an out-of-place sorting like mergesort, it would be very relevant to know how long pointers are and how big the memory overhead of a list is to estimate the total memory use.
Any suggestions, hints, recommendations?
Robert
|
|
|
|
|
hi i have a client server where my client is mobile and server is PC every thing works fine for me like sending and receiving data but the problem is when the there is no clients then the server will will be blocked by acceptandopen, so how can i make it close for some time if there is no clents connections.
|
|
|
|
|
I have dont have any background in java..
i have to make a simple prog with the basic concept of text twist i need some help pls.......
|
|
|
|
|
and you want help about what ?
what have you done so far in your application ?
|
|
|
|
|
i dont know how to use a word bank for the game....
i mean your suppose to have a text file were you get all the words from...right!?
in short I dont know how to get strings from a txt file....
|
|
|
|
|
i am searching a java project plz help me
zzzzzzzzzzzzzzzzzz
|
|
|
|
|
...and I want a beer. do you think you can help ?
|
|
|
|
|
Hey folks,
I have a question about writing the koch snowflake in java. When I compile my code I only get the snowflake on one side(so im guessing this is the koch curve instead) and I was wondering how do I get it to all the sides in order to form the snowflake? Here is my code, I know I am missing something but i'm not so sure what. thanks for the help:
import javax.swing.*;
import java.awt.*;
public class drawSnowflake extends JApplet
{
int level=0;
public void init()
{
String levelStr= JOptionPane.showInputDialog("Enter the recursion depth: ");
level = Integer.parseInt(levelStr);
}
public void paint(Graphics g)
{
int pointOne = 60;
int pointTwo = 120;
int pointThree = 160;
int pointFour = 140;
drawKochSide(g, level, pointOne, pointTwo, pointThree, pointFour);
}
private void drawKochSide(Graphics g,int lev, int x1, int y1, int x5, int y5)
{
int deltaX, deltaY, x2, x3, x4, y2,y3, y4;
if (lev<1)
g.drawLine(x1, y1, x5, y5);
else{
deltaX = x5-x1;
deltaY = y5-y1;
x2 = x1 + deltaX / 3;
y2 = y1+ deltaY / 3 ;
x3=(int) ((x1+x5)/2 + Math.sqrt(3.0)*(y1-y5)/6);
y3=(int) ((y1+y5)/2+ Math.sqrt(3.0)* (x5-x1)/6);
x4 = x1 + 2 * deltaX / 3 ;
y4 = y1 + 2 * deltaY / 3 ;
drawKochSide(g, lev-1, x1, y1, x2, y2);
drawKochSide(g, lev-1, x2, y2, x3, y3);
drawKochSide(g, lev-1, x3, y3, x4, y4);
drawKochSide(g, lev-1, x4, y4, x5, y5);
}
}
}
|
|
|
|
|