GTA3Rockstar Posted December 13, 2006 Share Posted December 13, 2006 I need to write a java program that outputs a word by the number of chracters it has in the word.. (eg Hello has 5 charactors so the output word repeat hello 5 times) but while using While statments! I have no clue how to do this one lol import java.io.*;// User picks starting and ending valueclass count{ public static void main (String[] args ) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); String inputString;int times; System.out.println( "Enter the word:" ); inputString = stdin.readLine(); times = inputString.length(); while ( count <= limit ) // less-than-or-equal operator { System.out.println(inputString); } }} Link to comment Share on other sites More sharing options...
GTA3Rockstar Posted December 13, 2006 Author Share Posted December 13, 2006 Write a program that computes the standard deviation of a set of floating point numbers that the user enters. First the user will say how many numbers N are to follow. Then the program will ask for and read in each floating point number. Finally it will write out the standard deviation. The standard deviation of a set of numbers Xi is: SD = Math.sqrt( avgSquare - avg2 ) Here, avg is the average of the N numbers, and avg2 is its square. avgSquare is the average of Xi * Xi. In other words, this is the average of the squared value of each floating point number. For example, if N = 4, say the numbers were: Xi Xi * Xi -----2.0 4.0 -----3.0 9.0 -----1.0 1.0 -----2.0 4.0 ----- ------ sum 8.0 18.0 then avg = 8.0/4 = 2.0 avg2 = 4.0 avgSquare = 18.0/4 = 4.5 SD = Math.sqrt( 4.5 - 4.0 ) = Math.sqrt( .5 ) = 0.7071067812 To do this you will need to do several things inside the loop body for each floating point value as it comes in: add it to a sum, square it and add it to a sum of squares. Then after the loop is finished apply the formula. Link to comment Share on other sites More sharing options...
facugaich Posted December 14, 2006 Share Posted December 14, 2006 I don't know crap about JAVA but I can give you a pseudo-code for the last one. read Nfor x = 1 to N read F sum = sum + f sum2 = sum2 + (f * f)end foravg2 = (sum/N)*(sum/N)avgS = sum2/NSD = sqrt( avgS - avg2 ) write SD And in your first post you meant without while loops? Link to comment Share on other sites More sharing options...
GTA3Rockstar Posted December 20, 2006 Author Share Posted December 20, 2006 I don't know crap about JAVA but I can give you a pseudo-code for the last one. read Nfor x = 1 to N read F sum = sum + f sum2 = sum2 + (f * f)end foravg2 = (sum/N)*(sum/N)avgS = sum2/NSD = sqrt( avgS - avg2 ) write SD And in your first post you meant without while loops? With! I got it though, week later but yeah thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now