Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Can Somebody please help me with my code?  RSS feed

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is the code for the random Password generator I am trying to write. If anybody runs this code, they will see the problems I am having. Can somebody please help me see what is wrong with this code? Thanks in advance.

 
lowercase baba
Posts: 12745
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi David, and welcome to the JavaRanch!

We're glad you're here, and folks are delighted to help. However, there are some things you can do to make life easier for others to help you.

Please take a few minutes and browse around this page. It will give you some tips on the best way to present your problem.

One of which is to actually tell other what the problem is. If you say "I was expecting A, but got B", often someone can skim your code and focus in on the problem. A lot of folks will read your post and say "Too much work to do all that, I'll skip it and move on".

The other main thing is to please use the 'code' tags. there are little buttons that you can use to insert special 'tags' that you then paste your code between. This preserves the formatting and makes it much easier to read.

I'll try and edit your post to have those, but if you could please post exactly what your problem is, you're more likely to get the help you need.
 
Ranch Hand
Posts: 136
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please put your code inside the [code] tag so that it is more readable
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi David, welcome to javaranch.

First of all you code has a lot of redundancy. You could have replaced your long code with this type of code



to get a similar result. Also when you add char values like this

System.out.println(firstChar + secondChar + thirdChar);

Then they are added as INTs instead of characters. So you should try this

System.out.println(""+firstChar + secondChar + thirdChar);
 
fred rosenberger
lowercase baba
Posts: 12745
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
to elaborate on Ankit Garg's post...

When java sees something like "firstChar + secondChar + thirdChar" it says

"hmm... what are these things on either side of the '+' character?"

In this case, they are char variables, which java believes are actually numeric values. What does it mean to add two numeric values? you calculate the sum. So, I would expect you are calculating some big sum and printing garbage.

The suggested solution is a little different. Java sees the firs thing is a String (albeit an empty one). It then says "how do I add a String and a number?" The answer is it converts the number to a string, then concatenates them together. if you have a whole series (as in your case), it figures out what to do with the first pair. Then, it takes the result of that (which is a String), and figures it out all over again with the next value, and keeps working its way down the list.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!