Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 29th, 2006, 03:21 PM
xreddawg909x xreddawg909x is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2005
Posts: 91 xreddawg909x User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 1 h 27 m 20 sec
Reputation Power: 4
Java code

if someone could look over this code i wrote and see if its done correctly i would greatly appreciate it.. i use netbeans and when i click "run" the ms dos window doesn't come up and run the program like dev c does for c++

its supposed to ask for integers and add'em up and give a sum at the end, it shouldn't accept negative integers.
Code:
import java.util.Scanner;


public class Main 
{
    
    /** Creates a new instance of Main */
    public Main() 
    {
    
    
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) 
    {
        // TODO code application logic here
       Scanner input = new Scanner( System.in );
        
        int hold, sum,option,count;
        sum = 0;
        do 
        {    
        count = 0;    
        hold = 0;
        System.out.print("Please enter non-negative integer to be added: ");
        hold = input.nextInt();
            while(hold<0)
            {    
              System.out.print("That number is negative, please enter another one");
              hold = input.nextInt();
            }
        sum = hold + sum;
        System.out.print("Do you wish to add another integer?(1 - yes 2 - no: ");
        option = input.nextInt();
        count = count +1;
        }while(option == 1);
    System.out.printf("The sum of the ", count,"integer(s) is ", sum);
    
    }
    
}

Reply With Quote
  #2  
Old August 30th, 2006, 09:29 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Have you tried running it from the commandline (and not Netbeans)?

I think Netbeans is trying to ask you for the input parameters, although it's been a while since I've used Netbeans.
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Java code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT