Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Correct declaration of method
Derryl Larson
Greenhorn
Posts: 13
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hey,
can anybody help me? Netbeans tells me it's an illegal start of expression during the initialisation of the interactWithUser method.
public class InvertLetter { /** * @param args the command line arguments */ public static void main(String[] args) { /** * String mit den Kleinbuchstaben. */ final String lowercase = "abcdefghijklmnopqrstuvwxyz"; /** * String mit den Großbuchstaben. */ final String uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public void interactWithUser() { System.out.println("Write a word: "); String input = (new java.util.Scanner(System.in)).nextLine(); try { this.interateString(input); } catch (Exception e) { System.out.println(e.getMessage()); this.interactWithUser(); } } public void interateString(String s) throws Exception { if (s == null || s.length() == 0) { throw new IllegalArgumentException("No empty input allowed"); } else { char[] lowercaseArray = this.lowercase.toCharArray(); char[] uppercaseArray = this.uppercase.toCharArray(); if (lowercaseArray.length != uppercaseArray.length) { throw new IllegalArgumentException("The strings don't have the same length"); } char[] string = s.toCharArray(); for (char c : string) { boolean lowerFound = false; for (int l = 0; l <= lowercaseArray.length - 1; l++) { if (!lowerFound) { if (lowercaseArray[l] == c) { System.out.println(uppercaseArray[l]); lowerFound = true; } } else { break; } boolean upperFound = false; if (!lowerFound) { for (int u = 0; u <= uppercaseArray.length - 1; u++) { if (!upperFound) { if (uppercaseArray[u] == c) { System.out.println(lowercaseArray[u]); upperFound = true; } } else { break; } } } if (!lowerFound && !upperFound) { throw new IllegalArgumentException("One of the chars you have chosen is not supported"); } } } } } } } }
Joanne Neal
Rancher
Posts: 3742
16
posted 9 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
You can't define one method inside of another. The declaration of the interactWithUser method is inside the main method.
Joanne
The human mind is a dangerous plaything. This tiny ad is pretty safe:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
How to compare to char array inside while loop
streams
Boolean Convert To Int Error
Default value for INT
cannot resolve symbol error
More...