<M/> 170 Why so serious? Featured Poster

Yeah, it only gives me the decimal format for mean?

<M/> 170 Why so serious? Featured Poster

Okay, so like this:

import java.text.DecimalFormat;
import java.util.*;
public class Mean {
     public static void main(String [] args){
    Scanner s = new Scanner(System.in);
        double[]x = new double[10];
        int i;
        for(i = 0;i < 10; i++){
            x[i] = s.nextDouble();
        }
        double mean = mean(x, i);
        double deviation = var(x);
        System.out.println("The mean is " + mean); 
        DecimalFormat df = new DecimalFormat("#.##");
        System.out.println("The standard deviation is " + df.format(deviation));    
}
public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    } 
    public static double mean(double[]x, double i){ 
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    } 
    public static double var(double[] x) {
if (x.length == 0) return Double.NaN;
double avg = mean(x, 10);
double sum = 0.0;
for (int i = 0; i < x.length; i++) {
    sum += (x[i] - avg) * (x[i] - avg);
}

return Math.sqrt(sum/(x.length-1));
 }
 }

but what about the decimal format for Standard Deviation?

<M/> 170 Why so serious? Featured Poster

So like this:

import java.text.DecimalFormat;
import java.util.*;
public class Mean {
    public static void main(String [] args){
        Scanner s = new Scanner(System.in);
            double[]x = new double[10];
            int i;
            for(i = 0;i < 10; i++){
                x[i] = s.nextDouble();
            }
            double mean = mean(x, i);
            double deviation = var(x);
            System.out.println("The mean is " + mean); 
            System.out.println("The standard deviation is " + deviation);
    }
public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    } 
    public static double mean(double[]x, double i){ 
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    } 
    public static double var(double[] x) {
        if (x.length == 0) return Double.NaN;
        double avg = mean(x, 10);
        double sum = 0.0;
        for (int i = 0; i < x.length; i++) {
            sum += (x[i] - avg) * (x[i] - avg);
        }
        DecimalFormat myFormatter = new DecimalFormat("#,##0.00");
        return Math.sqrt(myFormatter(sum/(x.length-1)));

    }
}
<M/> 170 Why so serious? Featured Poster

@AD, not that kind of stick man! like a little sketch, lol!

Granted, you never woke up...

I wish i mastered all programming languages (don't laugh)

<M/> 170 Why so serious? Featured Poster

Well... on the bright side, anchorman 2 wasn't that great...

<M/> 170 Why so serious? Featured Poster

Hmmm... i tried your code and it said: "cannot find symbol
System.out.println("The number of integers is " + count++);"

<M/> 170 Why so serious? Featured Poster

So like this:

import java.text.DecimalFormat;
import java.util.*;
public class Mean {
    public static void main(String [] args){
        Scanner s = new Scanner(System.in);
            double[]x = new double[10];
            int i;
            for(i = 0;i < 10; i++){
                x[i] = s.nextDouble();
            }
            double mean = mean(x, i);
            double deviation = var(x);
            System.out.println("The mean is " + mean); 
            System.out.println("The standard deviation is " + deviation);
    }
public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    } 
    public static double mean(double[]x, double i){ 
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    } 
    public static double var(double[] x) {
        if (x.length == 0) return Double.NaN;
        double avg = mean(x, 10);
        double sum = 0.0;
        for (int i = 0; i < x.length; i++) {
            sum += (x[i] - avg) * (x[i] - avg);
        }
        DecimalFormat myFormatter = new DecimalFormat("#,##0.00");
        return sum / myFormatter.format(Math.sqrt(sum of(squared(x - mean))/N-1));
    }
}
<M/> 170 Why so serious? Featured Poster

@dev90,

Like this:

import java.util.Scanner;
public class IntegerCount
{
public static void main(String[] args)
{
int num,count=0;
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer, the input ends if it is 0: ");
num = input.nextInt();
while(num!=0){
    count++;
    System.out.print("Enter an integer, the input ends if it is 0: ");
    num = input.nextInt();  
break;
}
System.out.print("total integers="+count);
}
int count++;    
}
<M/> 170 Why so serious? Featured Poster

Walking with Dinosaurs ... One of the worst movies I have ever seen!

And you watched it because?

<M/> 170 Why so serious? Featured Poster

Granted, your day was ruined because of all the other people's issues.

I wish i was a stick man!

<M/> 170 Why so serious? Featured Poster

I tried applying that, I still got an error? This is what i did:

import java.text.DecimalFormat;
import java.util.*;
public class Mean {
    public static void main(String [] args){
    Scanner s = new Scanner(System.in);
        double[]x = new double[10];
        int i;
        for(i = 0;i < 10; i++){
            x[i] = s.nextDouble();
        }
        double mean = mean(x, i);
        double deviation = var(x);
        System.out.println("The mean is " + mean); 
        DecimalFormat df = new DecimalFormat("#.##");
        System.out.println("The standard deviation is " + df.format(deviation));
}

public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    }
    public static double mean(double[]x, double i){
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    }
    public static double var(double[] x) {
        if (x.length == 0) return Double.NaN;
        double avg = mean(x, 10);
        double sum = 0.0;
        for (int i = 0; i < x.length; i++) {
            sum += (x[i] - avg) * (x[i] - avg);
        }
        DecimalFormat myFormatter = new DecimalFormat("#,##0.00");
        return sum / myFormatter.format(Math.sqrt(x.length - 1));

    }
}
<M/> 170 Why so serious? Featured Poster

Hmmmm... that doesn't seem to work because it just repeats the string.

<M/> 170 Why so serious? Featured Poster

Granted, you figured it out... and then forgot it.

I wish i was the joker.

<M/> 170 Why so serious? Featured Poster

I still think it should have been done in two parts instead of three.

Same here...

<M/> 170 Why so serious? Featured Poster

Is this correct? I wrote a decimal format and it doesn't work. how do i correct this:

    return sum / myFormatter.format(Math.sqrt(x.length - 1));

I will submit the full code if needed.

JamesCherrill commented: is already being discussed in OPs earlier thread -3
<M/> 170 Why so serious? Featured Poster

Okay, so you mean like this:

import java.util.Scanner;
public class IntegerCount
{
public static void main(String[] args)
{
 while(true){

    Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer, the input ends if it is 0: ");
int num = input.nextInt();

        if ( num == 0 ){
  System.out.println("No numbers were entered except 0");
}
else{
  System.out.println("The number of integers is " + count++);
}
}
}
}

I think i did it wrong? also, where do i put a break in this?

<M/> 170 Why so serious? Featured Poster

I was looking more at the 'costa coffee' on your staff t-shirt. Moonlighting are we Dani?

lol.

<M/> 170 Why so serious? Featured Poster

granted, you go to work instead.

I wish i lived in dubai

<M/> 170 Why so serious? Featured Poster

Yes, it is!!

I am guessing your setting up a mirror or a type of storage unit?

<M/> 170 Why so serious? Featured Poster

Okay, problem solved :D

I just basically refreshed chrome entirely :D

<M/> 170 Why so serious? Featured Poster

Check your computer preferences, it should say somewhere to stop automatic updates...

Also, what is your OS that your using? Windows, mac, etc.?

note, don't post questions like that in the community introduction

<M/> 170 Why so serious? Featured Poster

Welcome!

<M/> 170 Why so serious? Featured Poster

So here is what i have so far, am i using while(true) correctly? It says that is incorrect:

import java.util.Scanner;
public class IntegerCount
{
public static void main(String[] args)
{
 while(true){

    Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer, the input ends if it is 0: ");
int num = input.nextInt();

        if ( num == 0 ){
  System.out.println("No numbers were entered except 0");
}
else{
  System.out.println("The number of integers is " + num);
}
}
}
}
<M/> 170 Why so serious? Featured Poster

So doing it like this works but for some odd reason I can not do a decimal format very well...? This should be the last correction for this questions, thank you guys!

import java.text.DecimalFormat;
import java.util.*;
public class Mean {
    public static void main(String [] args){
        Scanner s = new Scanner(System.in);
            double[]x = new double[10];
            int i;
            for(i = 0;i < 10; i++){
                x[i] = s.nextDouble();
            }
            double mean = mean(x, i);
            double deviation = var(x);
            System.out.println("The mean is " + mean); 
            System.out.println("The standard deviation is " + deviation);
    }
public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    } 
    public static double mean(double[]x, double i){ 
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    } 
    public static double var(double[] x) {
        if (x.length == 0) return Double.NaN;
        double avg = mean(x, 10);
        double sum = 0.0;
        for (int i = 0; i < x.length; i++) {
            sum += (x[i] - avg) * (x[i] - avg);
        }
        DecimalFormat myFormatter = new DecimalFormat("#,##0.00");
        return sum / myFormatter.format((Math.sqrt(x.length - 1)));
    }
}
<M/> 170 Why so serious? Featured Poster

banning people who're critical of him from the white house press room takes care of that.

or people just don't bother with writing articles like that...

<M/> 170 Why so serious? Featured Poster

It says, "mark question solved" and i clicked it a few times... just to make it say the same exact thing

<M/> 170 Why so serious? Featured Poster

granted, there was nothing left...

I wish i was gandalf...

<M/> 170 Why so serious? Featured Poster

Elysium

<M/> 170 Why so serious? Featured Poster

@james, they are not exactly the same... the question began to change a bit on this thread, and so did the code.

Sorry, i won't "double post a thread" next time.

<M/> 170 Why so serious? Featured Poster

yo momma is so short she can surf on a popsicle stick

<M/> 170 Why so serious? Featured Poster

no deal, already got one (and 2 dogs)

a cockroach?

<M/> 170 Why so serious? Featured Poster

If nothing else, this thread has been worth it for the sheer joy of watching Alan get close to having a coronary at the keyboard as he attacks a completely virtual character with a brilliant display of Welsh wit. Yep, Welsh wit - who knew? ;)

This maybe a dumb question but who is alan?

<M/> 170 Why so serious? Featured Poster

According to a post on stackoverflow:

The dot (.) operator is used to access a member of a struct, while the arrow operator (->) in C is used to access a member of a struct which is referenced by the pointer in question.

The pointer itself does not have any members which could be accessed with the dot operator (it's acually only a number describing a location in virtual memory so it doesn't have any members). So, there would be no ambiguity if we just defined the dot operator to automatically dereference the pointer if it is used on a pointer (an information which is known to the compiler at compile time afaik).
<M/> 170 Why so serious? Featured Poster

@hicham, i am sure he has 99 problems and this ain't one of them anymore... ;)

<M/> 170 Why so serious? Featured Poster

It kind of reminds of that one stackoverflow feature they have (i would know because i was banned from their site a few times due to promoting daniweb :D).

Nice touch!

<M/> 170 Why so serious? Featured Poster

Welcome!

<M/> 170 Why so serious? Featured Poster

Welcome!

<M/> 170 Why so serious? Featured Poster

The author of this site has created a pretty nice one: http://the-echoplex.net/log/how-to-style-a-html-file-upload-control-using-css-and-javascript

it maybe pretty helpful but i think jorge's source maybe easier to follow.

<M/> 170 Why so serious? Featured Poster

I asked a question recently in the MySQL forum and when i look at my thread in the watched articles page, it says it has been marked solved even though i didn't mark it solved nor does the buttons on the thread indicate that it has been marked solved.

Is that a glitch or am I just seeing things?

<M/> 170 Why so serious? Featured Poster

on all of these it says that (in the error):
Table 'jstudent0.BOOK' doesn't exist

<M/> 170 Why so serious? Featured Poster

Here is the error log:

Your output has right initial contents, but is missing 1 characters at end
You have only a First Line Error

sdiff side by side difference your output versus solution....
Enter an integer: The pentagonal numbers are: 1 5 12 22 35    \ Enter an integer: The pentagonal numbers are: 1 5 12 22 35
<M/> 170 Why so serious? Featured Poster

Ummmm... i am kind of confused between the two.

@dev90, why do you have a (1) next to the while loop? May you do that on my snippet, it doesn't make sense at some parts (my tired and crazy logical side is kicking in)

<M/> 170 Why so serious? Featured Poster

i don't think i did it right...:

import java.util.Scanner;
public class Pentagonal {
public static void main(String[] args) {
int n,x,n1;
Scanner input = new Scanner(System.in);
System.out.print("Enter an integer: ");
n = input.nextInt();
n1=1;
System.out.print("The pentagonal numbers are: ");
while (n1<=n)
{
            x = (3*n1*n1 - n1)/2;
    if(n1==n)
System.out.print(x);
else
System.out.print(x+" ");
        n1++;
}   
}
}
<M/> 170 Why so serious? Featured Poster

there are quite a few flaws but finding the mean is pretty close (i need to figure out rounding on java) but standard deviation is way off.

This is what i got:

import java.util.*;
public class Mean {
    public static void main(String [] args){
        Scanner s = new Scanner(System.in);
            double[]x = new double[10];
            int i;
            for(i = 0;i < 10; i++){
                x[i] = s.nextDouble();
            }
            double mean = mean(x, i);
            double deviation = var(x);
            System.out.println("The mean is " + mean); 
            System.out.println("The standard deviation is " + deviation);
    }
public static double sum(double[] a) {
        double sum = 0.0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i];
        }
        return sum;
    } 
    public static double mean(double[]x, double i){ 
        if (x.length == 0) return Double.NaN;
        double sum = sum(x);
        return sum / x.length;
    } 
    public static double var(double[] x) {
        if (x.length == 0) return Double.NaN;
        double avg = mean(x, 10);
        double sum = 0.0;
        for (int i = 0; i < x.length; i++) {
            sum += (x[i] - avg) * (x[i] - avg);
        }
        return sum / (x.length - 1);
    }
}
<M/> 170 Why so serious? Featured Poster

Oh, that makes a whole lot of sense!
Last question and I will be marking this solved.

How do you make it so that there isn't an extra space at the end?

Apparently it displays like this: 1[]2[]3[]4[]5[]6[]
Rather than: 1[]2[]3[]4[]5[]6

(Those brackets are spaces)

Thanks!

<M/> 170 Why so serious? Featured Poster

Read the second line of my just above post. you have to get input into n variable and that's your limit of the pentagonal number sequences.

That is the part i don't understand on making? May you show me how to do it, i have an idea on how to do it but i don't think i understand it very well.

<M/> 170 Why so serious? Featured Poster

Am I getting close to what you mean?

import java.util.Scanner;
public class IntegerCount
{
public static void main(String[] args)
{
    Scanner input = new Scanner(System.in);
        System.out.print("Enter an integer, the input ends if it is 0: ");
int num = input.nextInt();
int input = input++;
        if ( num == 0 ){
  System.out.println("No numbers were entered except 0");
}
else{
  System.out.println("The number of integers is " + input);
}
}
}

I have a feeling i did something horrificly wrong in that snippet of code...

<M/> 170 Why so serious? Featured Poster

Wow, thanks! I have been beating my head against the wall on this problem.

<M/> 170 Why so serious? Featured Poster

You know how to find standard deviation.Then just write an algorithm or make a flowchart and implement it in a for loop, as you have done to find the mean.
It seems that you have'nt tried.

not exactly, i have tried but apparently i can't take it from paper to code that easily.
I am going to see what i can come up with in the background.

<M/> 170 Why so serious? Featured Poster

Unfortunately, no. The best deep dish apple pies I ever had were made by a friend of mine but he moved away several years back.

You should have him send you some or give you the recipe.