Need help with Java

Discussion in 'Software' started by kwyjibo, Oct 12, 2003.

  1. kwyjibo

    kwyjibo Private E-2

    Anyone know how to or know a website that describes how to make Java (programming language) count the number of entries someone makes WITHOUT having to import a seperate class file not included in the original kit?

    I can't use a class file that does this if it needs to be imported seperately, since I need to turn this in for my class.
     
  2. Genius Boy

    Genius Boy The Examinator

    Um, I'm not really sure of what you're asking, but I'll see if I can help.

    If you want to allow someone to enter information from a keyboard without having to have a separate keyboard class, put this into your Java program before anything else:

    import cs1.Keyboard;


    (edit: Indentations fixed. Thanks iamien)

    IE:
    Code:
    // ====================
    // | This is a Java Program |
    // ====================
    
    [B]import cs1.Keyboard;[/B] 
    
    public class Number
    {
        public static void main (String[] args)
        {
            int number;
            number = Keyboard.readInt();
            System.out.println ("You entered the number " + number);
        }
    }
    
    My apologies for any errors in coding - this is off the top of my head and I'm too lazy to compile it to see if it will run.


    The other thing that I think that you might be asking is simply to count the number of entries someone makes, and you already knew how to do what I just did up there.

    I don't know the structure of your program, but regardless, you can just create an int, say "count", and add one to it every time an entry is made. Then the final value of "count" will be equal to the number of entries made.

    Here's another really basic example. It is a for loop which will accept values until you enter 0, and will then display the number of values entered.
    Code:
    // =========================
    // | This is another Java Program |
    // =========================
    
    [B]import cs1.Keyboard;[/B]
    
    public class Count
    {
        public static void main (String[] args)
        {
            int count;
            int number;
            while (count != 0)
            {
                number = Keyboard.readInt();
                System.out.println ("You entered the number " + number);
                [B]count++;[/B]        //  or [B]count = count + 1;[/B]
            }
            System.out.println ("You entered " + count + " values");
        }
    }
    
    Once again I'm too lazy to test this to see if it works, so my apologies for any errors.


    I hope that this helps you solve your problem.
     
    Last edited: Oct 14, 2003
  3. iamien

    iamien Cptn "Eh!"

    use
    Code:
     [ /code]
    ie
    [code]
    // ==================== 
    // | This is a Java Program | 
    // ==================== 
    
    import cs1.Keyboard; 
    
    public class Number 
     { 
     public static void main (String[] args) 
      { 
      int number; 
      number = Keyboard.readInt(); 
      System.out.println ("You entered the number " + number); 
      } 
     } 
    
    My apologies for any errors in coding - this is off the top of my head and I'm too lazy to compile it to see if it will run.


    The other thing that I think that you might be asking is simply to count the number of entries someone makes, and you already knew how to do what I just did up there.

    I don't know the structure of your program, but regardless, you can just create an int, say "count", and add one to it every time an entry is made. Then the final value of "count" will be equal to the number of entries made.

    Here's another really basic example. It is a for loop which will accept values until you enter 0, and will then display the number of values entered.
    Code:
    // ========================= 
    // | This is another Java Program | 
    // ========================= 
    
    import cs1.Keyboard; 
    
    public class Count 
     { 
     public static void main (String[] args) 
      { 
      int count; 
      int number; 
      while (count != 0) 
       { 
       number = Keyboard.readInt(); 
       System.out.println ("You entered the number " + number); 
       count++; // or count = count + 1; 
       } 
      System.out.println ("You entered " + count + " values"); 
      } 
    
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds