Llist.java? llistnumbernode.java? PLEASE HELP
I'm programming linked-list. I know how to program, not that well though, but I don't understand how the linked-list works.
Here's what I got so far:
import java.util.*;
** Author: Yuan-Fang Wang
** The skeleton of a singly-linked-list class using interface
** DO NOT delete anything or change any parameters or return types
public class llist {
int length; // number of nodes in the list, for am empty list length = 0
node head; // must poinnt to the head (the first element) of the list
// interface definition of a node
public interface node {
public Object getValue(); // get stored KEY value
public node getNext(); // get next node
public void setNext(node l); // set next node
public int compares(node l); // compare values
public String toString(); // for printing
// constructor for a null list
public llist() {
head = null;
length = 0;
// constructor using the first node
public llist(node l) {
head = l;
length++;
// truncate the linked list to null
public void empty() {
//head.setNext(null);
// don't change anything here
public Enumeration getEnum() {
return new Enumeration () {
node current = head;
public boolean hasMoreElements() {
return (current!=null);
public Object nextElement() {
if (current==null) throw new NoSuchElementException("Linkedlist");
Object value = current;
current = current.getNext();
return value;
// return the number of nodes in the linked-list
public int getLength() {
return length;
// search for a node in the linked-list
// return its position in the linked list (the first node is 0)
// return -1 if the node is not found in the linked list
public int search(node elem) {
while(head != null){
// insert a node into the linked list
// return its position in the linked list (the first node is 0)
// return -1 if the node already in the linked list (no duplicated insert)
public int insert(node elem) {
if(head==null){
head = elem;
length++;
return 0;
else if(elem<head){
elem.setNext(head);
head = elem;
length++;
return 0;
else{
ptr = head;
while(ptr != null){
if(ptr == elem) return -1; //duplicate
else if(ptr.getNext() != null
return -1; // you must change this line to return the true insert result
// delete a node from the linked list
// return deleted node if is in the linked list and null otherwise
public node delete(node elem) {
return null; // you must change this line to return true delete result
// return the n-th node of the linked list
// return null if n is < 0 or larger than or equal to the current length
public node findNth(int n) {
return null; // you must change this line to return true findnth result
// print the list, DO NOT modify this method in anyway
public void printList() {
node ptr = head;
while (ptr!=null) {
System.out.print(ptr + " ");
ptr = ptr.getNext();
System.out.println();
// utility routine that will be used later, DO NOT modify this method
node findLast() {
if (head==null) return null;
node ptr = head;
while (ptr.getNext()!=null) {
ptr = ptr.getNext();
return ptr;
}And for llistnumbernode.java
** Author: Yuan-Fang Wang
** The skeleton of a singly-linked-list node using interface
** DO NOT delete anything or change any parameters or return types
public class llistnumbernode implements llist.node {
Number element; // stored element
llist.node next; // next node
public llistnumbernode (Number elem) {
// return the KEY value for comparison
public Object getValue() {
return null; // you must change this to return true result of getValue()
// get the next node in the list
public llist.node getNext() {
return null; // you must change this to return true result of getNext()
// set the next node in the list
public void setNext(llist.node l) {
// return 1 if this (self) > node l
// return 0 if this (self) == node l
// return -1 if this (self) < node l
public int compares(llist.node l) {
return -1; // you must change this to return true result of compares()
// DO NOT change this method
public String toString() {
return element.toString();
}Please HELPPPPP
Will someone please help!!!
Similar Messages
-
Pascal to Java Please help me!
I am truobled in creating a validation method for the user loging in....
As I am perfect at Pascal can anyone translate the following pascla code to Java Please help me with this.
PROGRAM USERLOGIN;
TYPE
USER_TYPE = RECORD
USERNAME : STRING[15];
PASSWORD : STRING[15];
END;
USFILE = FILE OF USER_TYPE;
VAR
USER: USER_TYPE;
CKUSER: USER_TYPE;
RECFILE : USFILE;
I,J : INTEGER;
BEGIN
WRITE('ENTER USERNAME:');READLN(CKUSER.USERNAME);
WRITE('ENTER PASSWORD:');READLN(CKUSER.PASSWORD);
FILESPEC :='USERFILE.USR';
ASSIGN(RECFILE, FILESPEC);
RESET(RECFILE);
WHILE NOT EOF(RECFILE) DO
BEGIN
READ(RECFILE, USER);
IF CKUSER.USERNAME = USER.USERNAME AND CKUSER.PASSWORD = USER.PASSWORD THEN
LOGIN
ELSE
WRITE('USER NOT FOUND');
END;
END.Thank youDon't bother:
http://forum.java.sun.com/thread.jsp?forum=54&thread=539277 -
Why the same name of process comes out in AIX , in java. please help me.
Hello.
I have two questions related to Jvm.
I've developed Job scheduler program which is doing somthing as the DB schedule is set in the way of Multi
thread. Currently , I'm in the process of testing this one. It is good , if in the normal case. However, When
doing Shell, if the application have so a lot to do the Shell, it has a little problem.
My developing environment is
OS : AIX 5.3
JRE : IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 AIX ppc-32 jvmap3260sr7-20091214_49398
(JIT enabled, AOT enabled)
nofiles(descriptors) 2000
maxuproc 4096 Maximum number of PROCESSES allowed
per user True
In order to execute Shell in My Scheduler program , I tested Runtimeexec() or ProcessBuilder.
The result of mine in the test , when the executed Shell got over 300 is
1. The jvm processes that I execute at the first time are shown up , after Shell go to the finish, the
processes are all in the disappearance again , and at last The processes that I executed at the first time are
remaining. It's like the process is duplicated process in the maximum of 70.
When I do shell about 200 to be executed simultaneously, Duplicated jvm about 3 appeared momentarily, then
disappeared, and also under 120, No duplicated case is found when under 120.
ps -ef result is below , when shell is excuted
UID PID PPID C STIME TTY TIME CMD
jslee 626906 1 0 11, May - 2:20 java -
DD2_JC_HOME=/source/jslee/JOB -Dfile.encoding=euc-kr jobserver.JobServerMain
jslee 1421522 626906 0
19:36:16 - 0:00 java -DD2_JC_HOME=/source/jslee/JOB -Dfile.encoding=euc-kr jobserver.JobServerMain
....Skip.....
jslee 4374620 626906 0 19:34:06 - 0:00 java -DD2_JC_HOME=/source/jslee/JOB -
Dfile.encoding=euc-kr jobserver.JobServerMain
(the process list about 60)
*the first question : Why a lot of duplicated jvm are shown up when in alot of shell to be executed ?
*the second question : As you can see above , How can I solve out the problem.
*Is there some option that I can set up when starting Jvm?
---Next question---
My developing environment is
OS : SunOS 5.8
JRE : Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Server
VM (build 16.0-b13, mixed mode)
nofiles(descriptors) 256
As shown obove , the value of descriptors is 256 .
My scheduler program executed 300 shell at the same time, in result my program was abnormalily
terminated after doing shell about 180.
the Exception info is
java.io.IOException: Cannot run program "sh": error=24, exceeding the number of opened files
at
java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at
java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
or
java.net.SocketException: exceeding the number of opened files at java.net.PlainSocketImpl.socketAccept
(Native Method)
또는
java.io.IOException: exceeding the number of opened files at
java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.checkAndCreate(Unknown
Source)
at java.io.File.createTempFile(Unknown Source)
*question : If I continuously request to open a file that go over system limit, is it possible for JVM to be
terminated?
*question : Is there a method that obtains state of System limit in the java library.
*question : what is the best solution to cope with ?
Please help me
=struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="registrationForm" type="ndlinh.struts.lab.RegistrationForm" />
</form-beans>
<action-mappings>
<action path="/register"
type="ndlinh.struts.lab.RegistrationAction" // action class
name="registrationForm" // form bean name
validate="false"
scope="request"
input="registration.jsp" >
<forward name="success" path="/jsp/success.jsp" />
<forward name="failure" path="/jsp/failure.jsp" />
</action>
</action-mappings>
</struts-config>HTH -
i'm very new to java and i'm getting an error in my application. i took 4 applications that compiled and worked separatly and i tried to combine them into one application. i'm getting the error: unreported exception java.io.IOException; must be caught or declared to be thrown, in lines 73,78,83,88,120,146,149,152,155 in the and it points at the keyboard.readLine() but everything i've tried just gives me more errors. please help anything and everything will be greatly appreciated. here it is, sorry about format i dunno how to straighten it in here:
// ^ ^
// (0)(0) A Happy Piggy Application
// Problems: 2.6,2.8,2.9,2.12 (oo)
// An application finds the total number of hours, minutes, & seconds, finds the distance
// between two points, finds the volume and surface area of a sphere, and adds up the change
// in a jar. First, the total hours, minutes, and seconds problem.
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class twoptsix
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
public static void main (String[] args) throws IOException
double hoursa, minutesa, secondsa;
String hours;
System.out.print ("Please enter a number of hours: ");
hours = keyboard.readLine();
hoursa = Double.parseDouble(hours); //asks programmer friendly user to enter hours
String minutes;
System.out.print ("Please enter a number of minutes: ");
minutes=keyboard.readLine();
minutesa = Double.parseDouble(minutes); //asks programmer friendly user to enter minutes
String seconds;
System.out.print ("Pretty please enter a number of seconds: ");
seconds = keyboard.readLine();
secondsa = Double.parseDouble(seconds); //asks programmer friendly user to enter seconds
double allseconds;
allseconds = (hoursa * 3600) + (minutesa * 60) + secondsa; //adds up all the seconds of the time entered
System.out.println ("You have: " + hours + " hours..."); //displays hours
System.out.println ("" + minutes + " minutes..."); //displays minutes
System.out.println ("and " + seconds + " seconds..."); //displays seconds
System.out.println ("to get whatever you need to done!"); //witty attempt at humor
System.out.println ("The total amount of seconds is: " + allseconds + " seconds."); //displays total seconds
// An application that finds the distance between two points when the points
// are given by the user.
double x1, x2, y1, y2, total, distance;
String xa;
System.out.print ("Please enter the 'x' coordinate of first point: ");
xa = keyboard.readLine();
x1 = Double.parseDouble(xa); //asks programmer friendly user to enter first x value
String ya;
System.out.print ("...also need the 'y' coordinate of first point: ");
ya = keyboard.readLine();
y1= Double.parseDouble(ya); //asks programmer friendly user to enter first y value
String xb;
System.out.print ("...and the 'x' coordinate of the second point: ");
xb = keyboard.readLine();
x2 = Double.parseDouble(xb); //asks programmer friendly user to enter second x value
String yb;
System.out.print ("...don't forget the 'y' coordinate of the second point: ");
yb = keyboard.readLine();
y2 = Double.parseDouble(yb); //asks programmer friendly user to enter second y value
total = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0); //squares the differences of values
distance = Math.sqrt(total); //finds the square root of the sum of the differences of the values
System.out.print ("E=mc^2...oh and,");
System.out.print ("the distance between point (" + xa +"," + ya +") and point("+
xb + "," + yb + ") is : " + distance);
// An application that takes the radius of a sphere and finds and prints
// the spheres volume and surface area.
double radius,volume,area;
String rad;
System.out.print("Please enter the radius of a sphere: ");
rad = keyboard.readLine();
radius = Double.parseDouble(rad); //asks programmer friendly user to enter the radius of a sphere
DecimalFormat fmt = new DecimalFormat ("0.####");
volume = ((4 * Math.PI * Math.pow(radius,3.0)) / 3) ;
System.out.println (" The sphere has a volume of:" + fmt.format(volume)); //finds and displays volume
area = ( 4 * Math.PI * Math.pow(radius, 2.0)) ;
System.out.print (" The Surface Area of the sphere is: " + fmt.format(area)); //finds and displays surface area
// An application that finds the total, in dollars and cents, of a number of quarters,
// nickels, dimes, and pennies in your piggy bank.
int pennies, nickels, dimes, quarters;
double money1;
screen.println("Empty your piggy bank and count the change, how many quarters ya have?: ");
int q = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of quarters
screen.println("How many dimes?: ");
int d = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of dimes
screen.println("How many nickels?: ");
int n = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of nickels
screen.println("How many pennies?: ");
int p = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of pennies
NumberFormat money = NumberFormat.getCurrencyInstance();
money1 = (.25 * q) + (.1 * d) + (.05 * n) + (.01 * p);
screen.println("You're rich! Total, you've got: " + money.format(money1));//finds and displays total moneyOk here is the working code as one long function:
// ^ ^
// (0)(0) A Happy Piggy Application
// Problems: 2.6,2.8,2.9,2.12 (oo)
// An application finds the total number of hours, minutes, & seconds, finds the distance
// between two points, finds the volume and surface area of a sphere, and adds up the change
// in a jar. First, the total hours, minutes, and seconds problem.
import java.io.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class twoptsix
static BufferedReader keyboard = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter screen = new PrintWriter(System.out, true);
public static void main (String[] args) throws IOException
double hoursa, minutesa, secondsa;
String hours;
System.out.print ("Please enter a number of hours: ");
hours = keyboard.readLine();
hoursa = Double.parseDouble(hours); //asks programmer friendly user to enter hours
String minutes;
System.out.print ("Please enter a number of minutes: ");
minutes=keyboard.readLine();
minutesa = Double.parseDouble(minutes); //asks programmer friendly user to enter minutes
String seconds;
System.out.print ("Pretty please enter a number of seconds: ");
seconds = keyboard.readLine();
secondsa = Double.parseDouble(seconds); //asks programmer friendly user to enter seconds
double allseconds;
allseconds = (hoursa * 3600) + (minutesa * 60) + secondsa; //adds up all the seconds of the time entered
System.out.println ("You have: " + hours + " hours..."); //displays hours
System.out.println ("" + minutes + " minutes..."); //displays minutes
System.out.println ("and " + seconds + " seconds..."); //displays seconds
System.out.println ("to get whatever you need to done!"); //witty attempt at humor
System.out.println ("The total amount of seconds is: " + allseconds + " seconds."); //displays total seconds
// } <----- MAIN FUNCTION USED TO END HERE!!!
//but we want to keep going so remove the bracket!
// An application that finds the distance between two points when the points
// are given by the user.
// { <-- other function used to start here, but now it continues
double x1, x2, y1, y2, total, distance;
String xa;
System.out.print ("Please enter the 'x' coordinate of first point: ");
xa = keyboard.readLine();
x1 = Double.parseDouble(xa); //asks programmer friendly user to enter first x value
String ya;
System.out.print ("...also need the 'y' coordinate of first point: ");
ya = keyboard.readLine();
y1= Double.parseDouble(ya); //asks programmer friendly user to enter first y value
String xb;
System.out.print ("...and the 'x' coordinate of the second point: ");
xb = keyboard.readLine();
x2 = Double.parseDouble(xb); //asks programmer friendly user to enter second x value
String yb;
System.out.print ("...don't forget the 'y' coordinate of the second point: ");
yb = keyboard.readLine();
y2 = Double.parseDouble(yb); //asks programmer friendly user to enter second y value
total = Math.pow(x2 - x1, 2.0) + Math.pow(y2 - y1, 2.0); //squares the differences of values
distance = Math.sqrt(total); //finds the square root of the sum of the differences of the values
System.out.print ("E=mc^2...oh and,");
System.out.print ("the distance between point (" + xa +"," + ya +") and point("+
xb + "," + yb + ") is : " + distance);
//second function used to end here...
//} <--- COMMENT OUT BRACKET SO WE CONTINUE
// An application that takes the radius of a sphere and finds and prints
// the spheres volume and surface area.
//{ <--- ANOTHER ONE TO COMMENT OUT
double radius,volume,area;
String rad;
System.out.print("Please enter the radius of a sphere: ");
rad = keyboard.readLine();
radius = Double.parseDouble(rad); //asks programmer friendly user to enter the radius of a sphere
DecimalFormat fmt = new DecimalFormat ("0.####");
volume = ((4 * Math.PI * Math.pow(radius,3.0)) / 3) ;
System.out.println (" The sphere has a volume of:" + fmt.format(volume)); //finds and displays volume
area = ( 4 * Math.PI * Math.pow(radius, 2.0)) ;
System.out.print (" The Surface Area of the sphere is: " + fmt.format(area)); //finds and displays surface area
// } <----- COMMENTED OUT FOR THE SAME REASON
// An application that finds the total, in dollars and cents, of a number of quarters,
// nickels, dimes, and pennies in your piggy bank.
//{ <----AND ANOTHER
int pennies, nickels, dimes, quarters;
double money1;
screen.println("Empty your piggy bank and count the change, how many quarters ya have?: ");
int q = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of quarters
screen.println("How many dimes?: ");
int d = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of dimes
screen.println("How many nickels?: ");
int n = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of nickels
screen.println("How many pennies?: ");
int p = (new Integer(keyboard.readLine())).intValue();//asks programmer friendly user to enter a number of pennies
NumberFormat money = NumberFormat.getCurrencyInstance();
money1 = (.25 * q) + (.1 * d) + (.05 * n) + (.01 * p);
screen.println("You're rich! Total, you've got: " + money.format(money1));//finds and displays total money
}P.S. To make the code formatted better put [ code ] before and [ /code ] after. It's not perfect, but a little better... -
M new to this forum + new to java please help me with file handling program
hi i want to make a file handling program where in i want to input a text file say f1 whose style is mentioned as below
aaa...bcd
aaabbc
acdce
a..dd
abbcd
now i want to write d out put of file f1 to file f2 but only those string entries widout any ... in them how to do that :-(( please help :((import java.io.*;
import java.lang.*;
class javcsse{
void javsce (){
BufferedReader in;
PrintWriter out;
String line;
try
in = new BufferedReader(new FileReader("e:\\cntcs\\n7.txt"));
out = new PrintWriter("e:\\cntcs\\n8.txt");
line = in.readLine();
while(line != null)
if(line.contains("...") && line.contains("....")){
break ;
else{
if(line.contains("cc"))
System.out.println(line+"\n");
out.println(line);
line = in.readLine();
in.close();
out.close();
} catch (Exception ex)
System.err.println(ex.getMessage());
public class javcse{
public static void main(String[] args) {
new javcsse();
}hey i wrote this code yet could u tell y is it still not working :(( -
I am new to java please help!!
please help ive got a method thta i wanto to use it in another class, but it does not work.
//prueba.java
import java.io.*;
public class prueba
public int numero3;
public int suma(int numero1,int numero2)
int numero3=numero1+numero2;
return numero3;
//prueba1.java
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import prueba;
public class prueba1 extends HttpServlet
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
PrintWriter out = res.getWriter();
int num1=1;
int num2=1;
prueba uno=new prueba();
out.println(uno.suma(2,3));
when i ty to complie this file it throws me thie errors:
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:4: cannot resolve symbol
symbol: class prueba
import prueba;
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
3 errors
Tool completed with exit code 1
both , prueba1.java and prueba.java are in the same folder.C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
C:\resin-2.0.b2\doc\content-manager\admin\web-inf\classes\prueba1.java:15: cannot resolve symbol
symbol : class prueba
location: class prueba1
prueba uno=new prueba();
^
2 errors -
Recursion in java. please help
I am writing a program for tree traversing as follows. The program is relatively long but please just focus on 2 lines with errors indicated.
import java.io.*;
import myBinaryTree;
class myBinaryTreeTest{
static int vertexArray[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 3, 3, 7, 9, 11, 5, 11};
static myBinaryTree treeArray[] = new myBinaryTree[10];
static myBinaryTree tree;
static pTwoChildNode nodeParent, nodeLeft, nodeRight;
static treeNodeData dataParent, dataLeft, dataRight;
public static void main(String[] args) {
for (int j=0; j<10; j++) {
treeArray[j]=new myBinaryTree();
boolean treeArrayEmpty;
int treeArrayEmptyIndex;
int treeArrayChildIndex, treeArrayParentIndex;
int vertexCollapseChild, vertexCollapseParent;
for (int i=0; i<20; i=i+2) {
vertexCollapseChild=vertexArray;
vertexCollapseParent=vertexArray[i+1];
treeArrayEmptyIndex=-1;
treeArrayChildIndex=-1;
treeArrayParentIndex=-1;
for (int j=0; j<10; j++) {
if (treeArray[j].isEmpty()) {
if (treeArrayEmptyIndex == -1) {
treeArrayEmptyIndex=j;
else {
dataParent = (treeNodeData)treeArray[j].getData();
if (vertexCollapseChild==dataParent.vertex)
{treeArrayChildIndex=j;};
if (vertexCollapseParent==dataParent.vertex)
{treeArrayParentIndex=j;};
if (treeArrayChildIndex != -1 && treeArrayParentIndex != -1)
{break;}
updateTreeArray(treeArrayChildIndex, treeArrayParentIndex,
treeArrayEmptyIndex, vertexCollapseChild,
vertexCollapseParent);
for (int j=0; j<10; j++) {
System.out.println("\nIn-order:");
preOTrav(treeArray[j].getRoot());
static void updateTreeArray(int c, int p, int e, int cc, int cp) {
// c=treeArrayChildIndex
// p=treeArrayParentIndex
// e=treeArrayEmptyIndex
// cc=vertexCollapseChild
// cp=vertexCollapseParent
System.out.println(c+" "+p+" "+e+" "+cc+" "+cp);
if (c != -1) {
if (p != -1) {
dataParent = new treeNodeData();
dataRight = (treeNodeData)treeArray[p].getData();
dataParent.vertex=dataRight.vertex;
nodeParent=new pTwoChildNode(dataParent);
nodeParent.setLeft(treeArray[c].getRoot());
nodeParent.setRight(treeArray[p].getRoot());
treeArray[Math.min(c, p)].setRoot(nodeParent);
treeArray[Math.max(c, p)].setRoot(null);
else
dataParent = new treeNodeData();
dataParent.vertex=cp;
nodeParent=new pTwoChildNode(dataParent);
nodeParent.setLeft(treeArray[c].getRoot());
dataRight = new treeNodeData();
dataRight.vertex=cp;
nodeParent.setRight(new pTwoChildNode(dataRight));
treeArray[Math.min(c, e)].setRoot(nodeParent);
treeArray[Math.max(c, e)].setRoot(null);
else
if (p != -1) {
dataParent = new treeNodeData();
dataRight = (treeNodeData)treeArray[p].getData();
dataParent.vertex=dataRight.vertex;
nodeParent=new pTwoChildNode(dataParent);
dataLeft = new treeNodeData();
dataLeft.vertex=cc;
nodeParent.setLeft(new pTwoChildNode(dataLeft));
nodeParent.setRight(treeArray[p].getRoot());
treeArray[Math.min(p, e)].setRoot(nodeParent);
treeArray[Math.max(p, e)].setRoot(null);
else {
dataParent=new treeNodeData();
dataParent.vertex=cp;
nodeParent=new pTwoChildNode(dataParent);
dataRight=new treeNodeData();
dataRight.vertex=cp;
nodeRight=new pTwoChildNode(dataRight);
nodeParent.setRight(nodeRight);
dataLeft=new treeNodeData();
dataLeft.vertex=cc;
nodeLeft=new pTwoChildNode(dataLeft);
nodeParent.setLeft(nodeLeft);
treeArray[e].setRoot(nodeParent);
static void preOTrav(pTwoChildNode n) {
if (n == null)
return;
dataParent=(treeNodeData)n.getData();
System.out.print(dataParent.vertex+" ");
preOtrav(n.getLeft());
preOtrav(n.getRight());
//problems are here!!!!!
class treeNodeData {
int vertex;
// data element2 -> a set of vertex fan;
It doesn't compile but with the message saying that can not resolve the symbol in preOTrav(n.getLeft()); and preOTrav(n.getRight());
Please help!preOtrav(n.getLeft());
preOtrav(n.getRight());Don't write preOtrav when you mean preOTrav. Java is case-sensitive.
Jesper -
New to Java, Please help
Hi, I was trying to play a game and came up with this java error (below), I uninstalled and reinstalled still no fix. I think i need a new class?, If anyone can explain the potential problem to me and help me fix it, that would be much appreciated. I'm a complete NEWB when it comes to java, I'm not even sure how to edit that code. so please remember to explain in the newbiest of newby answers. I am proficient with features of a computer just not java.
Java Plug-in 1.6.0_24
Using JRE version 1.6.0_24-b07 Java HotSpot(TM) Client VM
User home directory = C:\Users\Ethan
c: clear console window
f: finalize objects on finalization queue
g: garbage collect
h: display this help message
l: dump classloader list
m: print memory usage
o: trigger logging
q: hide console
r: reload policy configuration
s: dump system and deployment properties
t: dump thread list
v: dump thread stack
x: clear classloader cache
0-5: set trace level to <n>
load: class loader.class not found.
java.lang.ClassNotFoundException: loader.class
at sun.plugin2.applet.Applet2ClassLoader.fi… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.lo… Source)
at sun.plugin2.applet.Plugin2Manager.create… Source)
at sun.plugin2.applet.Plugin2Manager$Applet… Source)
at java.lang.Thread.run(Unknown Source)
Exception: java.lang.ClassNotFoundException: loader.class845681 wrote:
Hi, I was trying to play a game and came up with this java error (below), I uninstalled and reinstalled still no fix. I think i need a new class?, If anyone can explain the potential problem to me and help me fix it, that would be much appreciated. I'm a complete NEWB when it comes to java, I'm not even sure how to edit that code. so please remember to explain in the newbiest of newby answers. I am proficient with features of a computer just not java.If you want to learn how to program java, which is not the same as playing that particular game then you can start with the following link.
http://download.oracle.com/javase/tutorial/getStarted/index.html -
Fundamental questions in Java, please help to answer.
I am a beginner of a Java Programming. Although I had few programming experiences on Java. But there are few conceptal questions. Hope every experts can help to explain more to me.
1. How <b>Encapsulation</b> works in Java? Why is it needed? What benefits can be given from encapsulation? Can give some examples for me to know more?
2. How <b>Overloading</b> works in Java? Why is it needed? What benefits can be given from it in the extensibility of programs? Can give some examples for me to know more?
3. How <b>inheritance</b> works in Java? What benefits can be given from inheritance? Can give further explanation, such as class hierarchy for me to know more?
4. What is <i>object class</i> and <i>object distances</i> ? What is their differences?
5. What is <b>Reusability</b>? What benefits can it gives? Why it is needed? Can give me further examples?
Thanks for help very muchMaybe I'm not getting this, but you want one of us to give you a nice short answer convenient enough for you to copy down, right? Well, there aren't many people here that are willing to do that. There are many people who won't even bother answering homework questions. I don't mind, but you need to show us some work you've done, like the previous poster said. The effort has to come from you, not us. If you are learning Java, you must put some effort into it.
How can you get an answer out of us?
Example: I understand that inheritance is ..............., but I'm not sure about this part.............. Can anyone provide some clarification please?
Anyway, this question has been crossposted on at least 5 forums already, which I'm sure is one of the reasons people aren't bothering with this question. Please DO NOT CROSSPOST, it's considered poor forum etiquette.
Please don't take anything that I said negatively, but you have to understand that we are taking our time to respond to your queries, and asking us to provide short answers without doing any work on your part, and crossposting is not going to get you answers out of us.
Cheers -
Totally New in Java - Please help!!
Hi Dear all,
l am totally new in Java, and l facing one problem,and really hope can get some help from yours,please!
l need to write this program:
The program should do the following:
1. Input two fields: action (action: add / delete), and account number (any
digit or character)
2. if the action is "add" then the program adds one text line to a text
file.
"New account is <account number>"
3. create the text file if it is not already exist (in c:\)
4. When program runs again with new input values, a new line will be
appended to the same file.
5. if the action is "delete" then the program finds the record and removes
the text line from the file.
My problem is :
l just know that l need to create the user interface first,but l don't know how to go on??
Would you please show me some step how to solve these problem?
Many many thanks!!
BaoBaoI don't know about Swing. I never use it.
The stuff to create and manipulate files is in the java.io package.
You'll probably want to use java.io.FileReader and java.io.FileWriter.
Note that FileWriter has a constructor that lets you append and not overwrite.
I'll start you off with a test.
public class AccountListAddTest() {
public static void main(String[] argv) {
AccountList accts = new AccountList();
accts.add("abcdefg12345"); // arg is a hypothetical account number
}Write an AccountList class that'll work if you compile and run this test. After you run this test for the first time, the file should contain the string
New account is abcdefg12345.
This test assumes that the filename is hardcoded into the AccountList class. To keep it simple, make the add method create a new appending FileWriter each time, write, then close the writer. -
Adding binary numbers in java please help!!
Hello all, im a total newbie to java and i need your help urgently, i have two variables
that are integers, that store binary numbers i.e.
int tmpIntOne, tmpIntTwo;
tmpIntOne = 1010;
tmpIntTwo = 1110;
i want to add these numbers together and return a binary result so far when you add them together you get:
2120
however i would like a binary result so that
result = tmpIntOne + tmpIntTwo;
= 11000
Thank you.Hello all, im a total newbie to java and i need your
help urgently, i have two variables
that are integers, that store binary numbers i.e.
int tmpIntOne, tmpIntTwo;
tmpIntOne = 1010;
tmpIntTwo = 1110;These are not binary numbers. These are decimal numbers whose digits consist of ones and zeros. If you want to interpret the characters "010" as a binary number, then do
int tmp1 = Integer.parseInt("1010", 2);
etc.
i want to add these numbers together
int result = tmp1 + tmp;
and return a
binary result Adding two ints will give an int. Int's are always binary. If you want to display it as a binary String, as opposed to the usual decimal String, then, as suggested, use toBinaryString. -
Can u tell me how to check my computer ip address in java (please help me)
hi to all, can u tell me how to check my computer ip adress in java, what is the command for that
import java.net package in your code.
Then where you need to find the IP, please insert the following code.
InetAddress inAddr = InetAddress.getLocalHost();
String ipAddr = inAddr.getHostAddress();
That should do it.
Best Wishes,
Ramanujam -
My first step in Java, please help me.
I've just installed J2SDK1.4.0_03 and I'm reading the first pages of the Java tutorial.
I've created a work folder : C:\Java
I'm working with an msdos session of windows 2000
I've created my first example class, prthello.java with NotePad :
class prthello{
public static void main(String args[]) {
System.out.println("Hello World!");
I've successful compilated it (javac prthello.java) and generated the prthello.class
I've tried to execute it (java prthello) but it doesn't work and i receive the following message :
Exception in thread "main" java.lang.NoClassDefFoundError: prthello
The path should be correct (C:\Programmi\j2sdk1.4.0_03\bin) ,
any suggestions would be appreciate.
Thanking in Advance
Andrea Giussani
Milano, ItalyThank you for your suggestions, but i have already checked.
The path is ok, i've installed jsdk under folder "programmi" and the path is :
C:\>set path
Path=C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\PROGRA~1\IBM\CLIENT~1;
C:\PROGRA~1\IBM\CLIENT~1\Shared;C:\PROGRA~1\IBM\CLIENT~1\Emulator;C:\Programmi\F
ile comuni\Autodesk Shared\;C:\Programmi\j2sdk1.4.0_03\bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
prthello.java and prthello.class are in the same folder (C:\java) where i executed javac with success and java with the error above mentioned.
Any other suggestions ? Should I reinstall the JSDK ?
Thanking in advance,
Andrea Giussani -
Main method question in java, please help
Guys I have looked all over the internet, and cannot understand any of these questions: I would really appreciate any help on them. The first, and most important thing I would like to know is, what is static: what is a static int, or a static main method? Why is this necessary, and what does it do? Could you please provide an example? Also, why is String[] args necessary within the parameters of the main method? Is this so that it can execute it? Last thing is: objects. Where can I learn about them? I know they are made with the new operator, but don't understand their use? Could you explain why they are useful? Can you give them values? and how do they relate to the dot operator? After these are answered, I will be so happy because I will feel like I actually know a little bit. Right now, I'm just confused... Thank you so, so much in advance!
The first, and most important thing I would like to know is, what is static'static' means that the item concerned is associated with the class itself rather than an instance: so, it is accessible to all instances.
Could you please provide an example?
public static void main(String[] args)is an example, but you knew that. I don't really understand the question.
Also, why is String[] args necessary within the parameters of the main method?'args' receives the arguments you type on the command line after the class name or jar name, depending on how you invoke the application.
This is all covered in the documentation, which you should read before asking further questions.
Last thing is: objects. Where can I learn about them?If you don't know about objects you're not going to learn about them by asking questions on a forum. It's far too large a topic. Get yourself a book. -
Developing a shopping cart in java please help
Implement a shopping cart with following features.
1. Create items with required attributes.
2. Define shopping cart parameters
3. define stock values
4. Create an order
5. add to cart
6. Copy cart
7. remove item from cart
8. Check out
9. Print history.dhaval_shah wrote:
What do you need help with?he's ordering you to do it for him. Not even a "please" to make it sound like a request.
Of course we're not anyone's homework service (though a lot of kids seem to be under the impression that we are) so the kid can expected to be flamed and made fun of (which will likely lead to him getting agressive and abusive, leading to even more fun for us regulars and his eventual bannishment). -
Untar in JAVA, please help
Hi,
I have a tar file "test.tar" and it contains three .txt files. I know I can untar these three files into the filesystem first then reading their content. I just wonder is there a way that java can retrieve data directly from the tar file without untar it. I am looking forward for replies.
Thanks!Depends what you mean by "without untarring."
There's no way to retrieve the data without reversing tar's process. However, you don't have to write to the file system. I don't see a tar utility in the core API, but you should be able to find one with google. [EDIT: Or by visiting the URL that sabre posted. :-) ]
Barring that, executing tar xf and gobbling the output stream as described in the following article should work.
http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
Message was edited by:
jverd
Maybe you are looking for
-
New Pioneer DVD drive not recognized in profiler
I have used these forums many times to solve my problems so a big thanks to everyone who contributes. I've never had to actually ask a specific questions until now so here goes.... I have an e-mac running 10.3.9. My superdrive started to get flakey (
-
Random freezes-please, somebody, help me find a solution that works!
I feel a little stupid posting a new thread for what seems to be (at the moment) a rather common issue, but almost every related thread I've come across seems to pin the blame on different things, and I want to consolidate all that I know about what'
-
[CS3, JS] XML Rules: Get geoBounds of img Element in Same Branch
Hi, given the following xml structure: <root> <entry> <img href=""></img> <title></title > <subtitle></subtitle> </entry> <entry> <img href=""></img> <annotation></annotation> <title></title > <subtitle></subtitle>
-
Computer thinks iphone is a camera
weird problem everytime i plug in my 8gb iphone into any of my computers the computer picks it up as a camera itunes doesnt pick it up my computer sees it as a plain camera i tried changing settings but have no idea wat to do plz help...........
-
Autocomplete textbox function using in infopaht designer 2010
Hi i have created one textbox in infopath. In site page i added a CEWP and infopath form webpart. I add the code in HTML text editor, but i am getting javascript error. errors are below: - jquery is undefined - expected } This is my code <script src