|
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);
}
}
}
|
|
|
|
|
Hi vultron, I don't know if you really understand your code.
In your code, you clearly defined two points (only two), let's say point A and point B.
Coordinates of point A are given by :
int pointOne = 60;
int pointTwo = 120;
Coordinates of point B are given by :
int pointThree = 160;
int pointFour = 140;
Then you draw one side of the snowflake (the side A-B) by :
drawKochSide(g, level, pointOne, pointTwo, pointThree, pointFour);
What you have to do is to define a third point C and to draw the two other sides (B-C) and (A-C), so there's the final code of the paint method :
public void paint(Graphics g)
{
int pointOne = 50;
int pointTwo = 100;
int pointThree = 150;
int pointFour = 100;
int pointFive = 100;
int pointSix = 14;
drawKochSide(g, level, pointOne, pointTwo, pointThree, pointFour);
drawKochSide(g, level, pointFive, pointSix, pointOne, pointTwo);
drawKochSide(g, level, pointThree, pointFour, pointFive, pointSix);
}
Notice that in this example, the triangle ABC is not exactly equilateral because coordinates are integers.
|
|
|
|
|
Given the following classes, write the delete() method, which will delete all nodes equal() to Node n. delete() should return true if at least one node could be removed, and return false otherwise. Use Java syntax.Don’t use java API.
Public class DS {
public Node getStart() {
/* This method is written for you – it will return the first node */
}
public void setStart(Node n) {
/* This method is written for you – it will set the first node */
}
public boolean delete(Node n) { /* Provide code for this method */ }
class Node {
public boolean equal(Node n) { /* This method is written for you */ }
public Node getNext() {
/* This method is written for you – it will return the next node*/
}
public Node getPrevious() {
/* This method is written for you – it will return the previous node*/
}
public void setNext(Node n) {
/* This method is written for you – it will set the next node*/
}
public void setPrevious(Node n) {
/* This method is written for you – it will set the previous node*/
}
}
}
|
|
|
|
|
Read the posting guidelines.
1. we don't do homeworks here.
2. your code is not even formatted
3. you don't ask specific questions.
|
|
|
|
|
actually i forgot to submit my code here.
here is my code for delete(Node n)
----------------------------------
public boolean delete(Node n) { }
{
int var = 0;
Node head = new DS().getStart();
if (head.equal(n) )
{
head = head.getNext();
setStart(head);
var++;
}
Node n1 = null;
for (Node l = new DS().getStart() ; l != null; l = l.getNext())
{ if n1==null
if (l.equal(n))
{
n1.setNext(l.getNext());
var++;
}
}
if (var > 0)
return true;
else
return false;
}
modified on Thursday, September 25, 2008 9:02 AM
|
|
|
|
|
your code is still not formatted... don't you just see the code block button below the typing area ?
also, WTF is your question ???
|
|
|
|
|