| | |
Program does not work
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2008
Posts: 25
Reputation:
Solved Threads: 0
Hello everyone, I am AP COMPSCI A for my school and I trouble with this program. In the program you have to enter numbers from 1-100. And print a chart of how many numbers were between 1-10, 11-20 and so on. Like this:
1 - 10 |*
11- 20 |****
22- 30 |**
etc,
but for some reason my code doesn't work
1 - 10 |*
11- 20 |****
22- 30 |**
etc,
but for some reason my code doesn't work
/**
* @(#)NumChart.java
*
* NumChart application
*
* @author
* @version 1.00 2008/12/26
*/
import java.util.Scanner;
public class NumChart {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
int[] num= new int[15];
for(int i =0; i>15;i++)
{
System.out.print("Enter a number between 1-100: ");
num[i]= scan.nextInt();
while(i<1||i>100)
{
System.out.print("1-100 only please, Enter again: ");
num[i]= scan.nextInt();
}
}
int[] star= new int[10];
for(int j=0;j>10;j++)
star[j]=0;
for(int p=0;p<15;p++)
{
if(num[p]>=1&&num[p]<=10)
star[0]++;
else if(num[p]>=11&&num[p]<=20)
star[1]++;
else if(num[p]>=21&&num[p]<=30)
star[2]++;
else if(num[p]>=31&&num[p]<=40)
star[3]++;
else if(num[p]>=41&&num[p]<=50)
star[4]++;
else if(num[p]>=51&&num[p]<=60)
star[5]++;
else if(num[p]>=61&&num[p]<=70)
star[6]++;
else if(num[p]>=71&&num[p]<=80)
star[7]++;
else if(num[p]>=81&&num[p]<=90)
star[8]++;
else if(num[p]>=91&&num[p]<=100)
star[9]++;
}
System.out.print("1 - 10 | ");
for(int s=0;s<star[0];s++)
{
System.out.print('*');
}
}
} The line
is incorrect. It says, start at i=0, and while i>15 do the following code and add one to i. If i starts at 0 it is never greater than 15, so the code will never execute.
You have a similar error with the line
java Syntax (Toggle Plain Text)
for(int i =0; i>15;i++)
You have a similar error with the line
java Syntax (Toggle Plain Text)
for(int j=0;j>10;j++)
Last edited by darkagn; Dec 26th, 2008 at 8:04 pm. Reason: Found a second error
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend. •
•
Join Date: Jan 2008
Posts: 25
Reputation:
Solved Threads: 0
•
•
•
•
The line
is incorrect. It says, start at i=0, and while i>15 do the following code and add one to i. If i starts at 0 it is never greater than 15, so the code will never execute.java Syntax (Toggle Plain Text)
for(int i =0; i>15;i++)
You have a similar error with the line
java Syntax (Toggle Plain Text)
for(int j=0;j>10;j++)
Indeed; the entire point of the exercise was to make use of basic math tricks to come up with a compact solution and to exercise the basics of OOP.
Create a class which bears the responsibility of accepting a number and maintaining the state of which range appears how many times.
Like previously mentioned, use an array to maintain the occurrence count and calculate the range based on the number inputted rather than having thousands of conditionals.
Create a class which bears the responsibility of accepting a number and maintaining the state of which range appears how many times.
Like previously mentioned, use an array to maintain the occurrence count and calculate the range based on the number inputted rather than having thousands of conditionals.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- Reload this Page problems making python program work with py2exe (Python)
- Make program work on other PCs (VB.NET)
- How do i make my program work for 5 times and then Expire (VB.NET)
- the program don't seem to work (VB.NET)
- need help to make this program work (C++)
- Objects are not displaying in my program, also need to know how to work mouse clicks. (C++)
- hOW DOES THIS PROGRAM WORK? processor (C)
- qbasic program under Windows XP (Legacy and Other Languages)
- How to develop a new program (C++)
Other Threads in the Java Forum
- Previous Thread: Multi-line ToolTipText
- Next Thread: please help me to submit my minipro
Views: 413 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code color compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






