Returning &

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2005
Posts: 1
Reputation: B-80 is an unknown quantity at this point 
Solved Threads: 0
B-80 B-80 is offline Offline
Newbie Poster

Returning &

 
0
  #1
May 24th, 2005
i am making a program that makes java commands similar to c++ ones, i am trying to use an endl statesment as well, it works if i just type c.endl(); but if i use the endl in my actual string it doesnt
like this:
System.out.print("helloendl");

Also when i use my in method, it takes the word in, but then it doesnt return anything, or test, doesnt save it over the old variable. Yet if i was to print out the string variable in the "in" method, it would print the what was read in.
Idk why this is happening any ideas?


here is my code:

Test.java:

/* Test C Class
*Bobby Hashemi, Alex Karpov*/

public class test
{
public static void main(String[] args)
{
c c = new c();

String string = "Hello";

c.out("helloendl");

c.endl();

c.in(string);

c.out(string);
c.endl();

}
}

----------------------------------------------------------------------------------------------
c.java:

/* C++ command program, changes simple java commands to commands similar to C++
*Bobby Hashemi and Alex Karpov*/

public class c
{
c()
{
}

public void out(String string)
{
int q = 0;
String endl;
int length;
int end;

length = string.length();

end = length - 4;

endl = string.substring(end, length);

if (endl == "endl")
q = 1;

if (q == 1)
{
System.out.println(string.substring(0,length-4));
}
else if (q == 0)
{
System.out.print(string);
}
}
public void endl()
{
System.out.println();
}
public String in(String string)
{
EasyReader console = new EasyReader();

string = console.readLine();

String string1;

string1 = string;

return (string);
}
}
----------------------------------------------------------------------------
the q thing was an attempt at somthing i had it like if (endl == "endl") before, but that didnt work either, thanks for your help
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

Re: Returning &

 
0
  #2
May 25th, 2005
I don't undestand what your doing, but I can tell you why the q thing probably didn't work.

Instead of this:
if (endl == "endl")

do this:

if (endl.equals("endl"));

Other than that, I can't help because I don't understand what your doing.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 1143 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC