Banner

Sponsor

Login


Welcome Back!
Guest
Guest

Register

Lost your password?

77 users online



Java

Java

Currently viewing this thread: 1 (0 members and 1 guests)


Page 1 out of 2
Zwitterion

Zwitterion

Status: Offline!

Java

What is the syntax for Java to use a if - then goto command?

I used to be able to use IF F$ = something then goto something

something: commands

In qbasic. Is there a goto for java or is it all in separate classes?

kgx

kgx

Neverside Newbie
Status: Offline!

Do you know what methods are? Unlike BASIC, where you do GOTO LINENUMBER, Java doesn't use line numbers. So you need to write methods for a separate "process". Read on methods if you don't know what they are, and you will like it a little more than the GOTO stuff in BASIC Wink

Plau

Plau

Neverside Newbie
Status: Offline!

you just need to work with if- / if-else statements.....
like:

if( i == 0)
{
g.drawString ("The number is 0", 100, 50);
}

////

else
{
g.drawString ("The number isn't 0", 100, 50);
}

LoL yeah I know it isn't state of the art example, but don't know exactly what you need... Not quite familair with BASIC or any other compiled language Wink
Looks a lot like C++ thay say...... Well the only thing I know is that the standard things like if/else/etc look a lot like the ones used in php Smile

Zwitterion

Zwitterion

Status: Offline!

Would:

public int mult2(int p, int q){
int n;
n=(p*q)+2;
return n;
}

be an example of a method?

Zwitterion

Zwitterion

Status: Offline!

One last question:

How do I get a text input from a user and use it as a variable? I tried

Code:


KeyboardReader reader = new KeyboardReader();
String choice;
System.out.print("Enter your name");
choice = Keyboard.readString();

But it didn't work.

The_One1

The_One1

Status: Offline!

the method you had is right! what you would have to do is have something like:

int temp = 0, p = 1, q = 7;

temp = mult2(p, q)

and it would save what is n in the method in temp, you can also have methods that don't return anything, just replace the int by void!

and to read from keyboard you use:

var1 = keyboard.readLine();

to save it as int you use:

Integer.parseInt(keyboard.readLine());

because java takes all input as a String, and that would convert to integer

double.parseDouble(keyboard.readLine());

converts to double!

Have FUn!

kgx

kgx

Neverside Newbie
Status: Offline!

Let me give you something that will eiminate redundant statements for user input. Try the following method:

Code:

private static String readInput(){
try{
BufferedReader keyboard = new BufferedReader(
new InputStreamReader(System.in));
return keyboard.readLine();
}
catch (IOException e){}
return "";
}


Now, whenever you need user input, simply do:
String s = readInput;

And what The One said will apply to this as well Smile

PS: Just realised the difference in syntax for the "reader". Don't worry about it. I doubt if there's much of a difference.

Last edited by kgx, January 17th, 2003 09:44 AM (Edited 1 times)

Zwitterion

Zwitterion

Status: Offline!

Ok, I got the get user input figured out, but now I have another problem. When I get the text input from a user, I want it to send them to a different class and execute the commands there.

Code:


System.out.print("? ");
String subject = reader.readLine("");
if (subject == "Algebra")
System.out.println("Insert class");
else if (subject == choiceGeometry)
System.out.println("Insert class");
else if (subject == choicePhysics)
System.out.println("insert class");
else if (subject == choiceTrig)
System.out.println("insert class");

But nothing seems to happen after I type in what "subject" should be.

akuma

akuma

Status: Offline!

Zwitterion I removed the double post you had, which is probably why TheOne gave the response s/he did. Grin

TheOne I also removed the response to the post that I removed of Zwitterion's. In case you were wondering where it went.

heh, that's kind of confusing. Smile

Last edited by akuma, January 18th, 2003 12:41 AM (Edited 1 times)

kixster_2002

kixster_2002

Status: Offline!

that's because you cannot compare Strings in java using ==
you have to invoke the .equals method.

Code:


if ( subject.equals("choiceTrig"))
// would be true if the user input "choiceTrig"
// and then this fuction would call whatever
// you needed

Page 1 out of 2
Quick Jump:

Main Navigation


Site & Graphic Design by Aeon Tan
Developed by Jeremie Pelletier & Scott Roach


NeverAPI generated this page in 0.0088 seconds.