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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.