how can I find mode in java using arrays, if statement or for loop
I have another question
I want to ask the user to input number and then draw triangle like this

http://www.thebestdata.com/FileArchieve/2434_File1_1.PNG

how can I do this

Recommended Answers

All 4 Replies

question 1: what do you mean by, find mode?
question 2:
you enter a value, and based on that value, you can use two nested for loops:
the outer one, determines the height of your pyramid
the inner one, you should use to print the lines as you want them.

question 1: what do you mean by, find mode?

In statistics, the mode is the value that occurs most frequently in a data set or a probability distribution. If the distribution is a nice curve that's low at both ends and highest in the middle (like most are) it's the highest point on the curve

ah ok :), I'm more used to the dutch term.

well .. you could create an object FindOccurences that has two variables: int occurences, and Object (or int), the value you've found in the array.
then iterate over the array and each time you find, say, element 'A', you iterate over your array of FindOccurrences. if you find one with the element, you raise the variable occurences with one. if you don't find one, create one and set the variable occurences to 1.

when you've iterated over your entire array, find the FindOccurences element where occurences is the highest, and get the element, that's your mode.

I'm not saying this is the best, or easiest way, but it is a way :)

question 1: what do you mean by, find mode?
question 2:
you enter a value, and based on that value, you can use two nested for loops:
the outer one, determines the height of your pyramid
the inner one, you should use to print the lines as you want them.

to ask the user to enter whole number like (123 or 324) and then return the sum of the digits of the number buy using loop
the loop should be like this
loop untile the number that the user enter is z
inside the loop ( add number mod 10 to sum
set number /10 )
end loop

that what it's said in the assignment I couldn't understand it can you explain it please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.