User Profile

Collapse

Profile Sidebar

Collapse
dadimar
dadimar
Last Activity: Sep 19 '07, 03:30 PM
Joined: Sep 13 '07
Location: Iceland
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • dadimar
    replied to Count input values?
    in Java
    I did a little research. Here's my code. Tell me how you like it:

    Code:
    import javax.swing.JOptionPane;
    
    public class ListingBls99 {
      public static void main(String[] args) {
        
        String dataString = JOptionPane.showInputDialog(
                                                        "Enter a number:\n
    (The program will shut down and give you your resault if you press 0 )");
    ...
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    What I can't figure out is the unspecified amount of numbers which are put in. For example if it would always be 5 numbers this would be so much easier.
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    Code:
    int count = 1;
    int number  = read.nextInt();
    
    while (number != 0) {
        number = read.nextInt();
        if (number != 0) count++; 
        };
        System.out.println("Quit....");
    This is one way to count how often input numbers are put in.
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    I would add them together, count the amount of numbers and divide with the amount.

    What I learned is that this code reads the next input number, but overwrites it if I decide to continue with a new number I put in.

    Code:
    while (number != 0) {
    number = read.nextInt();
    };
    System.out.println("Quit");
    I put 25, 43 and 55 in. If I add System.out.prin tln(number) I get the last...
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    I'm trying to figure out how I can add the input numbers together and get the average. Am I on the right track?...
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    Code:
      
    while (number != 0) {
    number = read.nextInt();
    };
    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.
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    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");...
    See more | Go to post

    Leave a comment:


  • dadimar
    replied to Count input values?
    in Java
    Yes I know how to read the input, but how do I count it ?...
    See more | Go to post

    Leave a comment:


  • dadimar
    started a topic Count input values?
    in Java

    Count input values?

    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...
    See more | Go to post
No activity results to display
Show More
Working...