• Post Reply 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

I am not able to find my mistake in this

 
Greenhorn
Posts: 1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator






Here i just want to find the first vowel an break the string.But i got lots of error.Can anyone please help e to solve this problem?
 
Marshal
Posts: 76395
364
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Thank you for using the code button, but you didn't quite get it right. See this link. Don't worry;; I corrected the tags, and doesn't it look better unfortunately you still have some incorrect indentation; see lines 14‑16.
Please always tell us what goes wrong; I can see several errors, but maybe you are thinking of something different. Please tell us what you want to happen and what actually happens. Only then can we help.
 
Greenhorn
Posts: 5
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey there!

I'm working on the problem now, but I need more information. What is the main issue you are facing? Right now I can see errors in the code but I don't feel I have the full picture of what you WANT the code to do.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CB: welcome to the Ranch

I have an idea what OP wants to do, but we need to wait until he gives us more details.
 
Charles Byron
Greenhorn
Posts: 5
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Very nice to be here! I'm not super new to Java, but definitely not professional. Just trying to find a good place to practice, and this looks good!

But anyway, I have this so far:
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
CB: please don't get any closer to a complete solution. We have a policy shown in the header for this forum of allowing people to work ut problems for themselves. We believe people don't learn well if they are given a complete solution.
 
Charles Byron
Greenhorn
Posts: 5
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I believe this was posted in the Java in General forum which does not appear to have the same header, however I agree with that sentiment. I am mostly working through the problem on my end to try and better understand what OP is attempting to gain from this code. Apologies, I am still new to this website.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Apology accepted

I think it is supposed to be pig Latin, but we would need OP to give us the details to be sure about that.
 
Charles Byron
Greenhorn
Posts: 5
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was getting the same idea from the test code, but it's interesting that there is another class, "Repeating", in the original code. I'm wondering if this is the whole picture or a part of the desired code to set up a pig latin converter.
 
Rancher
Posts: 259
13
Eclipse IDE C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this might be too advanced of a way for a beginner, but it's how i would do it.
even if you don't want to do it this way, maybe something can be learned by this example.

 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That does look good, SF, but as you said, maybe too advanced for the current discussion. Since the OP hasn't come back to explain their full requirements, I shall forget anything about not giving complete solutions, and I shall assume they are trying to write pig‑Latin. I shall also assume it is meant to read, “anonymous,” rather than, “Anonymous”. If that isn't a big hint, I don't know what is
 
Charles Byron
Greenhorn
Posts: 5
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does appear that they need to add .toUpperCase() to the code or vice versa to prevent the code from breaking when character case input does not match the if function they are using. I also think that this can be done a lot easier with a HashSet, but I was attempting to use the code they wrote for the original fix I tried.

S Fox: Maybe we can collaborate to get this code working?
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Charles Byron wrote:. . . Maybe we can collaborate to get this code working?

You can do it on your own in ten minutes, surely? I shall make an executive decision that your app is supposed to take successive words from a Scanner reading from System.in, using a loop terminating when the input is “opstay”, and translate the input to pig‑Latin. I don't know what you are supposed to do with words starting with vowels.
 
S Fox
Rancher
Posts: 259
13
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i started collaborating on it before i saw campbells user requirements
i made it so that it will translate what you write and quit. it can be a single word, a sentence, or a paragraph.

punctuation marks will be improperly mixed into the words. that's the first thing that you should try to fix.
if there's no vowel, it just returns the original word because otherwise i'm not sure what to do in that situation.

example input/output is
input: i can speak in latin now
output: iay ancay eakspay inay atinlay ownay

 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not bad
There is one thing I don't like: using try with resources for System.in. When the try‑catch completes, you will have System.in closed and you can never reopen it for the same JVM.
 
S Fox
Rancher
Posts: 259
13
Eclipse IDE C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what's the correct way to do it? just never close the scanner, or close it when the program exits? i'm not quite sure of the consequences of not closing scanners or streams.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Leave the Scanner object to go out of scope when the program ends. I have a utility class so I can use one Scanner object per JVM.

That only applies to System.in, System.out and System.err. For everything else you will need to close Scanners, input streams, output streams, readers, writers, Formatters, etc. Otherwise there is a risk of keeping a resource open until your program terminates. For example a file may be inaccessible to everything else until you close whichever object you are using yourself. Try with resources, which you are obviously familiar with, is most probably the best way to close such resources.
 
Sheriff
Posts: 17065
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I’m not convinced that if you have a simple console program that you run with the java command that closing System.in will actually affect your ability to use  Scanner(System.in) in a subsequent run. I can buy the assertion that closing System.in while the program is still running in the same JVM will have that effect but not between separate runs. I don’t have my laptop to test this though.
 
Campbell Ritchie
Marshal
Posts: 76395
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:. . . affect your ability to use  Scanner(System.in) in a subsequent run. . . . closing System.in while the program is still running in the same JVM will have that effect . . .

I did say, “for the same JVM.” Of course a new JVM will have a new Stream instance represented by System.in.
Have just tried it on Bash.
 
Bartender
Posts: 1891
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I didn't see what you expected for output, but looking at just your variable names, I modified your code in one line and got this output for 'y' (not a good variable name):

nymousAnay

Before Vowel: "An" (since A is capitalized, your code won't find this one)
Aftervow: nymous

y = aftervow + beforevowel + "ay" ==> nymous+An+ay = nymousAnay

(line I modified:  String aftervow = x.substring(i + 1);)

Also, it's good practice that your program should state expected results and any assumptions you're making.

This code runs without errors (when you add this main method to your class):



HOPE THIS HELPS.

-- mike
 
Let me tell you a story about a man named Jed. He made this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic