473,568 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Count input values?

9 New Member
I'm trying to write a program that reads unspecified number of positive and negative values, counts them and computes the average of the input values, not counting zeros. The program should end with the input 0 and display the average as a floating point number.

What can I use to count the input values?

Example: If I type 1, 2 and 0 the average should be 1.5

Ps: I'm a beginner...
Sep 13 '07 #1
21 11290
r035198x
13,262 MVP
I'm trying to write a program that reads unspecified number of positive and negative values, counts them and computes the average of the input values, not counting zeros. The program should end with the input 0 and display the average as a floating point number.

What can I use to count the input values?

Example: If I type 1, 2 and 0 the average should be 1.5

Ps: I'm a beginner...
Read about the Scanner class (for reading the input) and try the program. You should make use of a while loop.
Post if you get stuck with the code.
Sep 13 '07 #2
dadimar
9 New Member
Read about the Scanner class (for reading the input) and try the program. You should make use of a while loop.
Post if you get stuck with the code.
Yes I know how to read the input, but how do I count it ?
Sep 13 '07 #3
Nepomuk
3,112 Recognized Expert Specialist
Yes I know how to read the input, but how do I count it ?
How would you count them in real life? Think about that, then you'll find the answer.

PS.: Have you found out yet, if the number is positive or negative? That's the first step of course.

Greetings,
Nepomuk
Sep 13 '07 #4
r035198x
13,262 MVP
Yes I know how to read the input, but how do I count it ?
The while loop
Sep 13 '07 #5
dadimar
9 New Member
I have no idea. Am I on the right track:

import java.util.Scann er;

public class Skilaverkefni2{
public static void main(String[] args) {

Scanner read = new Scanner(System. in);

System.out.prin tln("text: ");

int number = read.nextInt();

while (number != 0) {

}

System.out.prin tln("Quit");
}
}
Sep 13 '07 #6
r035198x
13,262 MVP
I have no idea. Am I on the right track:

import java.util.Scann er;

public class Skilaverkefni2{
public static void main(String[] args) {

Scanner read = new Scanner(System. in);

System.out.prin tln("text: ");

int number = read.nextInt();

while (number != 0) {

}

System.out.prin tln("Quit");
}
}
1.) Use code tags for posting code
2.) Try it on the compiler and see what it does or doesn't do.
Sep 13 '07 #7
dadimar
9 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. while (number != 0) {
  3. number = read.nextInt();
  4. };
  5. System.out.println("Quit"); 
This gives me the ability to enter unspecified amount of numbers until I decide to quit by entering 0 as an input.
Sep 13 '07 #8
dadimar
9 New Member
Expand|Select|Wrap|Line Numbers
  1.  
  2. while (number != 0) {
  3. number = read.nextInt();
  4. };
  5. System.out.println("Quit"); 
This gives me the ability to enter unspecified amount of numbers until I decide to quit by entering 0 as an input.
I'm trying to figure out how I can add the input numbers together and get the average. Am I on the right track?
Sep 13 '07 #9
Nepomuk
3,112 Recognized Expert Specialist
I'm trying to figure out how I can add the input numbers together and get the average. Am I on the right track?
Yes, you are. Now think about how you can calculate the average - how would you do it in real life?

Greetings,
Nepomuk
Sep 13 '07 #10

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

Similar topics

2
3955
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the checkboxes are picked up using $_POST and put into session variables. On page two there is another form which is simply a condensed version of the...
6
10608
by: M.Kamermans | last post by:
I have an XSLT script that has to operate on some particularly nasty XML to turn it into a SQL databse, but 'entries' in the XML aren't actually unique, so their unique identifier is useless. I need to somehow create crosslinked tables using the XSLT, but can only do this by maintaining a counter for each line I write. Is there a way to...
4
3007
by: ZyPhiX | last post by:
Hi, I've got a little problem: I'm trying to make a webpage with a few scrolldown menu's and I want to count the values of them. In the scrolldown menu's are no numeric values but the have to represent one. I hope I can explain it a little bit better: Scrolldownmenu 1: - Option A (name A) --> (this has to represent te value 10 for...
10
2861
by: Jon | last post by:
I want to count the number of instances of a certain string(delimiter) in another string. I didn't see a function to do this in the framework (if there is, please point me to it). If not, could someone let me know if the method I've used below is efficient or if there is a better way to do it, as these will be rather large strings I'm...
68
6770
by: Martin Joergensen | last post by:
Hi, I have some files which has the following content: 0 0 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 0 0 0 0 0
0
4087
by: tania | last post by:
i have this table in my database: CREATE TABLE FILM( F_ID INT(5) NOT NULL AUTO_INCREMENT, F_TITLE VARCHAR(40) NOT NULL, DIRECTOR_FNAME VARCHAR(20) NOT NULL, DIRECTOR_LNAME VARCHAR(20) NOT NULL, TYPE VARCHAR(30) NOT NULL, DURATION TIME , YEAR_RELEASE YEAR NOT NULL, DESCRIPTION TEXT,
22
12434
by: MP | last post by:
vb6,ado,mdb,win2k i pass the sql string to the .Execute method on the open connection to Table_Name(const) db table fwiw (the connection opened via class wrapper:) msConnString = "Data Source=" & msDbFilename moConn.Properties("Persist Security Info") = False moConn.ConnectionString = msConnString moConn.CursorLocation = adUseClient...
2
2827
by: nick048 | last post by:
Hi, I am a new user of C++ and I am learning this language. I want to resolve this example: 1) I have an indefinite sequence of integer (from 0 to 36) as Input; 2) I want to know the maximum number of occurrences and its value. eg Input: 0, 2, 5, 2, 23, 11, 11, 23, 15, 17, 25, 11, 23, 18, 23 (Ctrl+z) Output: Value is 23 Occurences is 4 ...
3
10006
by: cmartin1986 | last post by:
I have written a sql query and I need it to return 0 when it doesn't find any matches to my criteria. I have tried adding iif statements, tried sum, and just Count, all of these methods work fine to return the values when it finds matches, but i need it also to return a 0 when there are no matches. Here is what I got. SELECT "CAL Recieved"...
0
7913
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. ...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7659
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...
0
7962
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...
0
6274
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...
1
5496
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...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.