473,804 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program Question (arrays)

12 New Member
Ok so I had to develop a class in which I needed to count the number of times someone enters in a number from a selected group of numbers from 1 to 100. In this case we're talking about groups of 10. Since I'm not very good with arrays (it was advised I use an array of counters, but since my professor has yet to teach us do so, that wouldn't really work anyway). So I decided to get creative and do it this way (not finished yet, only worked up to 60 so far). The funny thing is, the first 3 groups work out perfectly, but after that it's almost like it won't read any input, any help would be appreciated in this matter, thanks ahead guys.

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2. public class TestingNew
  3. {
  4.     public static void main (String[] args)
  5.     {
  6.         Scanner scan = new Scanner (System.in);
  7.         final int MAXNUMBER = 101;
  8.         int[] list = new int [MAXNUMBER];
  9.  
  10.  
  11.         System.out.println ("How many integers between 1 and 10 will you enter?");
  12.         int num = scan.nextInt();
  13.  
  14.         System.out.println ("How many integers between 11 and 20 will you enter?");
  15.         int num1 = scan.nextInt();
  16.  
  17.         System.out.println ("How many integers between 21 and 30 will you enter?");
  18.         int num2 = scan.nextInt();
  19.  
  20.         System.out.println ("How many integers between 31 and 40 will you enter?");
  21.         int number = scan.nextInt();
  22.  
  23.         System.out.println ("How many integers between 41 and 50 will you enter?");
  24.         int number1 = scan.nextInt();
  25.  
  26.         System.out.println ("How many integers between 51 and 60 will you enter?");
  27.         int number2 = scan.nextInt();
  28.  
  29.  
  30.         System.out.print ("1 - 10 | ");
  31.         int index = 0;
  32.         while (index < num)
  33.         {
  34.  
  35.             System.out.print ("*");        
  36.             index++;
  37.         }    
  38.  
  39.         System.out.println(" ");
  40.  
  41.         System.out.print ("11 - 20 | ");
  42.         for (int index1 = 0; index1 < num1; index1++)
  43.         {
  44.             System.out.print ("*");
  45.         }
  46.  
  47.         System.out.println (" ");
  48.  
  49.         System.out.print ("21 - 30 | ");
  50.         for (int index2 = 0; index2 < num2; index2++)
  51.         {
  52.             number = number;
  53.             System.out.print ("*");            
  54.         }
  55.  
  56.         System.out.println(" ");
  57.  
  58.  
  59.         System.out.print ("31 - 40 | ");
  60.         for (int i = 0; i < number; i++);
  61.         {
  62.             System.out.print ("*");
  63.         }
  64.  
  65.         System.out.println(" ");
  66.  
  67.  
  68.         System.out.print ("41 - 50 | ");
  69.         for (int index3 = 0; index3 < number1; index3++);
  70.         {
  71.             System.out.print ("*");
  72.         }
  73.  
  74.         System.out.println("");
  75.  
  76.  
  77.         System.out.print ("51 - 60 | ");
  78.         for (int index4 = 0; index4 < number2; index4++);
  79.         {
  80.             System.out.print ("*");
  81.         }
  82.  
  83.         System.out.println("");
  84.  
  85.     }
  86. }
  87.  
Mar 10 '08 #1
1 1266
BigDaddyLH
1,216 Recognized Expert Top Contributor
It's a common oversight:

Expand|Select|Wrap|Line Numbers
  1. for (int i = 0; i < number; i++);
Note the unwanted semicolon at the end of this line. That causes the loop body to be the empty statement instead of the block that follows. Remove these offending semicolons.

Note this has nothing to do with arrays since your code does nothing with arrays!
Mar 10 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
2208
by: Chris Mantoulidis | last post by:
There must be some tips to make a program quicker. I guess more than 50% of ppl here will say "avoid the if-s". Yeah I know this makes a program quicker but some times an "if" is inevitable, isn't it? What are some tips to make a program quicker? TIA, cmad
7
4124
by: jmac | last post by:
Greetings fellow programmers, I have created a C program that has a few bugs and would like to get some help with working them out. Here is a list of the problems that I am experiencing: - The program calls for the input to be added in one line (? 100 Smith 24.98), but my right now my program skips a line each time for example: ? 100
60
3351
by: Dominique Léger | last post by:
Hello guys, I'm kinda new to C, and I'm having a hard time with strings. What I'm trying to do is a simple function that trims spaces & tabs at the beginning of a given string. For example, I want this: " Hello World" to become this: "Hello World". At first glance, my function seems to work, but returns some strange values... Here's my code (please pardon the mess):
8
1605
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of type strings (containing 20 elements). c) One of type char (containing 30 elements).
34
29906
by: Tom | last post by:
I'd greatly appreciate advice and code snippets on how to create a ram disk within a C/C++ program. I also need to be able to determine the free space. Thanks in advance for any help.
4
1986
by: canteyn | last post by:
Ok here is my problem. I am coding a program that uses 3 different functions, and the end result is that the program reads in (x,y) points from a file, and then outputs those points to another file, and then calculates the area of the points(which form a polygon). I am able to compile the program just fine, but every time I try and run the program I just get a "segmentation fault". It may be in regards to my arrays, in fact I am almost sure...
23
2274
by: mike3 | last post by:
Hi. I seem to have made some progress on finding that bug in my program. I deactivated everything in the bignum package that was used except for the returning of BigFloat objects. I even crippled all the constructors. So now all the operations and constructors that were used do is just return BigFloats but no memory is actually accessed at any point, nor is any allocated. However, when I reenable those parts of the constructor that...
16
5840
by: Nkhosinathie | last post by:
hi, i'm writing a program that is using 4 arrays of pointers to char,called article,noun,verb and preposition.the program should create a sentence by selecting a word at random from each array in the following order:article,noun,verb preposition,,article and noun.as each word is picked,it should be concatenated to the previous words in an array that is large enough to hold the entire sentence. the words should be separated by spaces.when the...
6
1668
by: jason | last post by:
Hello, I have a question about what kind of datastructure to use. I'm reading collumn based data in the form of: 10\t12\t9\t11\n 24\t11\t4\t10\n ..... I now have a structure which allows me to access the data like this: x->row.coll.value.d;
20
3795
by: cowboyrocks2009 | last post by:
Hi, I need help to automate my code to take data from input file. Also I need to create it as a function so that I can pass it to some other program. I am new to Java so having a bit limitation to do this. My tab delimited Input File looks like this:- 21 p 13e 0 62 1 580001 andrew -14.53 -13.95 0 0 21 p 13d 63 124 580002 1160001 andrew -13.95 -13.37 0 0 21 p 12g 311 364 2900000 3385714 john -11.63 -11.14 0 0 21 q 11.1a 1274 1321...
0
9714
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9594
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10351
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10096
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7638
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5534
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.