I really need help. I did the code, but I know it is all wrong. I am not sure how to fix it. This program has boggled me for a week.
I am watching the growth of the function. First I have to calculate a function after entering the value of x from a prompt. Then I have to use printstars to print the relative size for values from 1 to 10.
I am a bad programmer. I already know this.
Does anyone see anything wrong with my code?

:cry:

import java.io.*;
import java.math.*;


public class GrowthofaFunction {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		double x;
		int y;
		
		System.out.println("Enter value for x: ");
		public int calculateFunction(int x);
		{
			y = x + (x*x) + Math.pow(2,x);
			return y;
		}
		
		//printStars has input x
		   for (int y = 0; x > y; x++)
		   {
			   x = y/10;
		   }
		      System.out.print("*");

	}
    return;
}

I don't see any code taking input. Look into the bufferedreader.

I don't see any code taking input. Look into the bufferedreader.

Yeah that would be a solution. I knew something important was missing like that. :o

I will post the new code and hope that someone else could tell me what i did wrong. I don't think I did like horribly bad. But I know those printStars are wrongggggg. I never got increments and decrements even when I took C++.

Sad huh? :eek:

import java.io.*;
import java.math.*;
import java.util.*;


public class GrowthofaFunction 
{

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		public void calculateFunction(int x)
		{
			final int y1;
			final int y2;
			final int y;
			
			Scanner stdin = new Scanner(System.in);
			
			System.out.print("Enter value for x: ");
			x = stdin.nextInt();
			
			y1 = x + (x*x);
			y2 =(int) (Math.pow(2,x));
			y = y1 + y2;
			return;
			
			
             //	printStars has input x
			
			for (int i = 0; i > 0; i++)
			   {
				   x = y/10;
			   }
			      System.out.print("*");
			      return;
			 
			      
		}  
		
}

This is the updated code. I just accomplished. I hope this is right. Anyone see anything worth checking? I finally figured it out. Thank God.

Yeah, you've got a problem with the loop. Fix that, and then I'll take a look at the rest.

for (int i = 0; i < 10; i++)
			   {
				   x = y/10;
			           System.out.print("*");
			   }

You want to increment while a condition is true. For instance, in this case we start with:
i = 0;
which is our couting variable.

The second thing is the condition. The condition here is:
i<10;

That means we will keep looping as long as 'i' is less than 10.

The third thing in the loop, is the increment statement. In this example:

i++

means that for each round in the loop, 'i' will be incremented by one. The first time you program runs the looping looks like this;


i=0
i IS less than 10
i is incremented by one(now it is 1)
a start is printed

Second time:
i=1 //from the first increment
i is still less than 10
i is incremented //now equals 2
Another star is printed.


It goes on and on until the looping condition is not true(i is greater than or equal to 10).

Opps, you might want to take the x = y/10 out of the loop. There's no reason to do that 10 times!

Opps, you might want to take the x = y/10 out of the loop. There's no reason to do that 10 times!

See apparently I am suppose to take the answer of the function and then print the stars.........say for instance the answer is 62 then divide it by 10 and i will get 6 stars because you know it is truncated.

So now I am guess, I am doing that wrong.

for (int i = 0; i <= 0; i++)
			   {
				   y = stdin.nextInt();
				   i = y/10;
			   }
			      System.out.print("*");
			      return;

Ok I changed it up a little bit. I am trying here. There is nothing better than that right. :o

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.