| | |
Project Help: Growth of a Function
![]() |
•
•
Join Date: Dec 2004
Posts: 22
Reputation:
Solved Threads: 0
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:
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:
Java Syntax (Toggle Plain Text)
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; }
•
•
Join Date: Dec 2004
Posts: 22
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by server_crash
I don't see any code taking input. Look into the bufferedreader.
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:
•
•
Join Date: Dec 2004
Posts: 22
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
Yeah, you've got a problem with the loop. Fix that, and then I'll take a look at the rest.
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).
Java Syntax (Toggle Plain Text)
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).
•
•
Join Date: Dec 2004
Posts: 22
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by server_crash
Opps, you might want to take the x = y/10 out of the loop. There's no reason to do that 10 times!
So now I am guess, I am doing that wrong.
Java Syntax (Toggle Plain Text)
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
![]() |
Similar Threads
- CODING QUESTION: What is the MOST importanting thing to do when...... (Computer Science)
- Borland C++ vr 4.5 (C++)
- need help on word counter (C++)
Other Threads in the Java Forum
- Previous Thread: Socket help needed: How to listen without blocking program
- Next Thread: Nim Strategy
| Thread Tools | Search this Thread |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image inetaddress integer integration intellij j2me java javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






