NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Script Help

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
gorton33



Joined: 06 Mar 2017
Posts: 1

PostPosted: Mon Mar 06, 2017 5:39 am    Post subject: Script Help Reply with quote

I simple just need some help to fix this script.
yes and no are defined as strings
My code:
String yes = "Yes";
String no = "No";
boolean nameIsGood = true;
String name = "";
while (nameIsGood) {
System.out.print("First Please Enter your Name: ");
name = in.nextLine();
if (name.length() < 1) {
System.out.println("Your name must be at least one character long!");
System.out.println("Try again! \n");
} else {
nameIsGood = false;
}
}

String changeName = "";
System.out.print("Are you sure you want (" + name + ") as your name?" + "(Yes) or (No): ");
changeName = in.next();

boolean nameIsGood2 = true;
while (nameIsGood2) {
if (changeName.equalsIgnoreCase(yes)) {
nameIsGood2 = false;
} else if (changeName.equalsIgnoreCase(no)) {
System.out.print("Please Enter your new Name: ");
name = in.nextLine();
if (name.length() < 1) {
System.out.println("Your name must be at least one character long!");
System.out.println("Try again! \n");
}else{
nameIsGood2 = false;
}
} else {
System.out.println("You did not enter (Yes) or (No)");
System.out.println("Try again! \n");
}
}
System.out.println("Hi " + name + "!");
System.out.println();

XOXOXOXO
end of my code. when i enter no for are you sure you want *name* as your name my output is:

First Please Enter your Name: jk
Are you sure you want (jk) as your name?(Yes) or (No): no
Please Enter your new Name: Your name must be at least one character long!
Try again!

Please Enter your new Name: hey
Hi hey!

XOXOXOXO
end of output. So the question is can anyone help me here? why does it print out your name must be at least one character long and then allows me to change the name?

Any help someone can provide would be Amazing!

Thanks,
Gorton33
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo