Win a copy of Rust Web Development this week in the Other Languages forum!

Suresh Sajja

Ranch Hand
+ Follow
since May 12, 2009
Suresh likes ...
Java
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
8
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Suresh Sajja

Invoking super.clone will eventually invoke Object’s clone method,
Object's clone method first verifies if class of this object implements cloneable, then creates new instance of the class and initializes all the fields with same values as in original object.

9 years ago
let me take a step back here, why don't you start with "what is object"?
Then you will be able to judge what object to use.
9 years ago

James Dekker wrote:




1. If loop is not coded correctly. semicolon is added at the end of if condition.
by doing so, if condition is evaluated and does nothing. and the next two lines are executed for all cars irrespective of if result.
2. you may have to call "name.equalsIgnoreCase(car.getMake)"

If you can tell, I printed out the value of the car.getMake() String and inside the console / shell, it ways says this:

car.getMake(): Toyota

car.getMake(): Corolla // I assume you meant Ford here

9 years ago
Alex Munoz,

From this post and your previous topic, i understand that you are looking for help on
1. reading a file.
2. Storing the maze in an array.

To get you started, please go through the tutorial on I/O streams.
9 years ago
Your code doesn't follow conventions. [No indentation, class name starts with lowercase letter]. Please read post on coding conventions here

The idea is to build an application that will ask a user to input a sequence of 8 letters (random sequence of vowels or consonants), then use a dictionary to find and display the longest word using the letters provided.


I would suggest you to keep the code aside for a moment and to start thinking about the problem.

If i divide the problem

Part 1:
How to read user input characters?Do we intend to read exactly 8 characters? Do we use array (or what data structure) to store those characters? Any input validations?

Part 2:
Do we have to construct dictionary? or is it supplied with problem? If we have to construct the dictionary, what are the specs?

Part 3: [Core logic]
How do we compare Part 1 and part 2 and output longest word?

I hope this will help you to get started.

9 years ago
Looks like a duplicate post, but with more details about the context of question.

https://coderanch.com/t/598716/java/java/File-input
9 years ago
Going beyond your post:

There is a bug in this line

int mid = (lowerBound + upperBound)/2;

It should be

int mid = lowerBound + ((upperBound- lowerBound ) / 2);

Please read more from Google research blog



9 years ago

tom davies wrote:



Shouldn't this comparison be " if(sortedArray[mid] == numberToFind) " ?
9 years ago
Welcome to the Ranch

1. Please use code tags while posting the code
9 years ago

Will Kasper wrote: Does situation 1 initialize the values at compile time while situation 2 initializes the values at run time?



Initialization happens at run time.
In case of situation 1, the initialization code is actually put in to the constructor by the compiler
9 years ago
No difference. Both serve the same purpose.

Situation 1 works well when initialization can be put in one line.
Situation 2 works well when complex initialization process and error handling is required.
9 years ago

1. Your class name "searchFile" starts with lowercase letter. The first letter will be uppercase. Please read here for code conventions. CodeStyle
2. Your code is all cluttered in main method. If i have to write this, i would start with the following skeleton. If the code is separated as various methods, it has got more advantages: easy to read, easy to understand, less error-prone and many more..

9 years ago
Oh! i misread you original post.

I would approach this problem in two steps,

1. To come up with a algorithm that generate all the permutations of N numbers
2. filter the list to hold only good permutations



9 years ago
Java compiler is platform independent. Compiler just convert java code into byte code.

JVM is platform dependent because
1. it must convert the byte code into machine language.
2. executes the corresponding machine-language instructions as well.

Machine instructions are different for different platforms. So different platforms need different JVM. So JVM is platform dependent
9 years ago