Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Few Java questions:
How to prompt user for input?
How to save input from user in an array?
How to average numbers in an array?
How to compare numbers?
How to print information back to the user?
The scenario is as follows: let the user to input 10 numbers into an array. Then loop through the array and average it. Then loop through the array again and compare each value against the average and print the number (and/or loop index) if it is lower than the average of the 10 numbers user entered.
Read the array.
Calculate the average.
Loop through the array
check if it has value less than average
if yes print the index
if no check for the next
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am trying to learn java but I am lost with the challenge below
what it does:
0. prompt user for a String
1. read a String from the user
2. print the character in the string with the lowest Unicode
3. continue until the user enters the string 0
Example:
enter a string (end with 0): ksjdhfasksjsh
first: a
enter a string (end with 0): ksdjdhfgKKFHDFGASDJSDHsjsdhjasjhdsj
first: A
You need to:
Set a char variable min to Integer.MAX_VALUE;
iterate thru the String and get each character
Compare to min. If less than min assign char to min
when done the min value will be the lowest value character
so print it.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I tried it with Sieve Of Eratosthenes, but I quickly run into the problem that my boolean array can't go past Integer.MAX
How should I approach this problem?
Arrays
Use 2 or more dimensional maps. So converting long to two integers (for accessing the arrays) will be like this:
array[N / Integer.MAX_VALUE][N % Integer.MAX_VALUE] where N is long and array is the boolean array.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'm trying to find out an algorithm that returns the number that has more occurrences in an array that contains number from 0 to 9 and that has a complexity of n.
I though to using an HashMap but it would require n^2
If anyone can write the code down,i'd prefer in Java but pseudocode is the same
Use ten counters (one per digit), scan the array and increment the counters corresponding to the digits. (You are actually computing the histogram of the digit frequencies.)
Report the digit with the largest counter.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So, I'm trying to calculate a list of number to eventually sort, so I only want the final result of this for loop.
for (int anno=startyear; TimePeriod>=anno;anno++) {
System.out.println(anno);
}
Where anno = 1995 and I am counting to the current day, I end up getting a result that slowly counts up, where it first counts at 1995, then it counts 1995 and then 1996, and so on.
How do I only get the end result for use in my program? The result that would simply be 1995-2014. Not the repeats.
edit: Forgot to mention I need every number in between 1995-2014 as well
You shouldn't need a loop for this, assuming your TimePeriod variable equals 2014 then just do the following to print out the desired result:
System.out.println(startyear+"-"+TimePeriod);
That will print out:
1995-2014
You already know the final value: it's TimePeriod. If that's all you need, just use that and get rid of the loop:
System.out.printf("%d-%d", startyear, TimePeriod);
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to generate random numbers . Now, I want to generate a new set of random numbers in a way that that increases the probability of returning the numbers that were generated earlier.What is the best way of achieving this ?
I dont know if predefined functions exist or not, but I have something in mind that you can try.
Make an ArrayList of the numbers. (eg. if you want to generate from
0to30, then make an ArrayList of Integers from 0 to 30).
Shuffle the ArrayList(Collections.shuffle())
Pick the first 2 numbers.
Then, just add those 2 numbers into the ArrayList as many times as you want the probablity to shift towards them.
Shuffle again and pick
You can store that values on array.
And you can have a random condition also for having a new pair of number or pick randomly on your array.