0

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

2
Contributors
1
Reply
2
Views
12 Years
Discussion Span
Last Post by server_crash
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.