Back | Reverse | Quick Reply | Post Reply |

can't stop it
Link | by on 2010-11-04 06:54:43
I have to make a program as a homework. now I have a problem that the memo can't stop loop.... it should have been stopped if we write down "end memo"

here's the program:
import java.util.*;

public class Zeta
{
public static void main( String [] args )
{
Scanner in = new Scanner(System.in);
int input;
int a;
String ls;
int o=0;
String asg;
do {

System.out.print("1.Draw \n");
System.out.print("2.Write Memo \n");
System.out.print("3.Exit \n");
do {
System.out.print("Input choice [1..3] : ");
input=in.nextInt();
} while (input<1 || input>3 );
if (input == 1) {
do {
System.out.println("1.gambar segitiga: ");
System.out.println("2.gambar persegi: ");

System.out.println("3.gambar jajargenjang: ");
System.out.println("4.balik ke menu awal ");
do {
System.out.print("input choice [1..4]");
a=in.nextInt();
} while (input<1 || input>4);
if (a == 1) {
System.out.print("input size:");
int g= in.nextInt();
}
else if (a == 2) {
System.out.print("input size:");
int l=in.nextInt();
}
else if(a==3){
System.out.print("input size:");
int ret=in.nextInt();
}
else if(a==4){
break;
}
} while (true);
} else if (input == 2)
{
System.out.println("write memo:");
do{

ls = "end memo";
o++;
System.out.print(o);
asg=in.nextLine();

}while(asg != ls);

}
else if (input==3)
{
break;
}
} while (true);


}
}



I need to know how to stop it


Re: can't stop it
Link | by Pioneer Plus on 2010-11-04 23:15:32
Well as you know, String object is rather unique in Java Technology.
There were some differences in the heap memory as per se literal pool bla... bla.. bla.

You should make the code as bellow:

do{
ls = "end memo";
o++;
System.out.print(o);
asg = in.nextLine();
if (asg .equals(ls)) break;
} while(asg != ls);


Actually the (asg != ls) is not used. The important part is equal() operator.
Hope this will help :)

Left_SG Right_SG

Re: can't stop it
Link | by on 2010-11-06 21:10:16
wow, Pioneer plus, thank you very much for your help :)


Re: can't stop it
Link | by Pioneer Plus on 2010-11-07 01:39:24
You're welcome, I've been into Java since 2 years ago... once I looked at the source code; I'm getting moved to fix it.

It's me Pioneer, actually. Still remember? I've just been into this mode all the time. XD

Left_SG Right_SG

Re: can't stop it
Link | by on 2010-11-09 07:44:48
I thought so!!!!

so it was you... how are you, long time no see...
ehm, post in AIH?

now, how about help me in this:

I need to make a java stopwatch
the user will be asked to input the time(hh:mm:ss:ms)(hour:minutes:second:miliseconds) and the stopwatch will count down the time
,

all I could think is using do-while inside do-while
this' all I have made:

do{
second=60;
do{
second--;
System.out.print(second);
}while(a>=0)}while(min>=0)

but there's a lot of problems there, like if the user input 50 in the second, it'll be reseted to 60... so I was thinking to put if-else outside, make an

if(second<60){do
{second--;
System.out.print(second);
}while(a>=0)}
else{
do{
second=60;
do{
second--;
System.out.print(second);
}while(a>=0)}while(min>=0)
}

well, but now I confused myself... can you help?


Back | Reverse | Quick Reply | Post Reply |

Copyright 2000-2024 Gendou | Terms of Use | Page loaded in 0.0026 seconds at 2024-12-30 12:45:30