| | |
Returning &
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2005
Posts: 1
Reputation:
Solved Threads: 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
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
![]() |
Similar Threads
- returning by reference (C)
- returning an array? (C++)
- ASP.net/Stored Proc & Login Verification (ASP.NET)
- Returning a correct python list (Python)
- RH Linux, eDirectory & 3rd party apps (Novell)
- C++ BASICS ==> Pointers, Call by Reference/Value, Inheritance, Functions & Arrays (C++)
- XP very slow & CPU usage very high (new install) (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Newby girl needing desparate help
- Next Thread: 80x86 Headache!! Help!! Urgent!!
Views: 1143 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool keyword linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






