IT Community - Software Programming, Web Development and Technical Support

newbie question in java

This is a discussion on newbie question in java within the Java Programming forums, part of the Software Development category; Yeah. I can do any number with the fixed code above. I'll see what I can do. Thanks for ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > Java Programming

Register FAQ Members List Calendar Mark Forums Read

Reply
 
Thread Tools Display Modes
  #11  
Old 03-26-2008, 01:05 AM
latchu latchu is offline
D-Web Trainee
 
Join Date: Sep 2007
Posts: 21
latchu is on a distinguished road
Default Re: newbie question in java

Yeah. I can do any number with the fixed code above. I'll see what I can do.

Thanks for all the help/replies guys.this community brings out me a lot.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12  
Old 03-28-2008, 03:17 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 319
amansundar is on a distinguished road
Default Re: newbie question in java

Take a look at this link
http://java.sun.com/docs/books/tuto...lts/arrays.html
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13  
Old 03-28-2008, 03:21 AM
latchu latchu is offline
D-Web Trainee
 
Join Date: Sep 2007
Posts: 21
latchu is on a distinguished road
Default Re: newbie question in java

I don't know if I did it the long way or whatever but I got it to work.
Code:
   1.
      import java.io.*;
   2.
      import javax.swing.*;
   3.
       
   4.
          class ArrT
   5.
      {
   6.
       
   7.
      public static void main (String[] args) throws IOException {
   8.
              String inData;
   9.
              int[] anArray;
  10.
             
  11.
              anArray = new int[20];
  12.
             
  13.
              anArray[0] = 0;
  14.
              anArray[1] = 0;
  15.
              anArray[2] = 0;
  16.
              anArray[3] = 0;
  17.
              anArray[4] = 0;
  18.
              anArray[5] = 0;
  19.
              anArray[6] = 0;
  20.
              anArray[7] = 0;
  21.
              anArray[8] = 0;
  22.
              anArray[9] = 0;
  23.
              anArray[10] = 0;
  24.
              anArray[11] = 0;
  25.
              anArray[12] = 0;
  26.
              anArray[13] = 0;
  27.
              anArray[14] = 0;
  28.
              anArray[15] = 0;
  29.
              anArray[16] = 0;
  30.
              anArray[17] = 0;
  31.
              anArray[18] = 0;
  32.
              anArray[19] = 0;         
  33.
                               
  34.
              inData = JOptionPane.showInputDialog (null, "Enter an Integer Value.") ;
  35.
              anArray[0] = Integer.parseInt ( inData); // convert inData to int
  36.
             
  37.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  38.
              anArray[1] = Integer.parseInt ( inData);
  39.
             
  40.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  41.
              anArray[2] = Integer.parseInt ( inData);
  42.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  43.
              anArray[3] = Integer.parseInt ( inData);
  44.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  45.
              anArray[4] = Integer.parseInt ( inData);
  46.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  47.
              anArray[5] = Integer.parseInt ( inData);
  48.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  49.
              anArray[6] = Integer.parseInt ( inData);
  50.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  51.
              anArray[7] = Integer.parseInt ( inData);
  52.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  53.
              anArray[8] = Integer.parseInt ( inData);
  54.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  55.
              anArray[9] = Integer.parseInt ( inData);
  56.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  57.
              anArray[10] = Integer.parseInt ( inData);
  58.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  59.
              anArray[11] = Integer.parseInt ( inData);
  60.
              inData = JOptionPane.showInputDialog (null, "YOUSUCK! ENTER ANOHTER ONE.");
  61.
              anArray[12] = Integer.parseInt ( inData);
  62.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  63.
              anArray[13] = Integer.parseInt ( inData);
  64.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  65.
              anArray[14] = Integer.parseInt ( inData);
  66.
              inData = JOptionPane.showInputDialog (null, "This isn't over...");
  67.
              anArray[15] = Integer.parseInt ( inData);
  68.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  69.
              anArray[16] = Integer.parseInt ( inData);
  70.
              inData = JOptionPane.showInputDialog (null, "Suck it blue!");
  71.
              anArray[17] = Integer.parseInt ( inData);
  72.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  73.
              anArray[18] = Integer.parseInt ( inData);
  74.
              inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
  75.
              anArray[19] = Integer.parseInt ( inData);
  76.
             
  77.
             
  78.
             int sum = anArray[0] + anArray[1] + anArray[2] + anArray[3] + anArray[4] + anArray[5] + anArray[6]
  79.
             + anArray[7] +  anArray[8] + anArray[9] + anArray[10]  + anArray[11] + anArray[12] + anArray[13] +
  80.
             anArray[14] + anArray[15] + anArray[16]  +anArray[17]  + anArray[18] + anArray[19];
  81.
             int avg = sum/20;
  82.
             
  83.
              System.out.println ("Sum of your sorry list of numbers is:" +sum);
  84.
              System.out.println ("The average is:" +avg);
  85.
             
  86.
              System.out.println ("Good-bye for now, suckahfish!"); //always executed
  87.
      }
  88.
       
  89.
      }

Edit:

I did have a question though. Because I'm having the user input their own value for each of the 20 numbers does it matter that I initialized each of the arrays at 0? Any information here is appreciated. Thanks for keeping up with me.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14  
Old 03-28-2008, 03:23 AM
amansundar amansundar is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 319
amansundar is on a distinguished road
Default Re: newbie question in java

Do

Code:
 1.
      for(int i =0;i < anArray.length;i++ ) {
   2.
            System.out.println(anArray[i]);
   3.
      }

before that string of anArray[i] = 0; to find out for yourself what values the array locations are initialized to.
__________________
cheers
Aman
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15  
Old 10-01-2008, 09:58 PM
detta detta is offline
D-Web Trainee
 
Join Date: Sep 2008
Posts: 11
detta is on a distinguished road
Default Re: newbie question in java

Java is a programming language originally developed by Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities.
________________

promotional gifts Body Kits
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16  
Old 10-03-2008, 05:59 AM
kiranzcontent kiranzcontent is offline
D-Web Trainee
 
Join Date: Oct 2008
Posts: 3
kiranzcontent is on a distinguished road
Default Re: newbie question in java

I'm sorry dude....i cant help you right away....

let me learn the best and i will help you then...


________________

hotel manhattan beach Bacca di Acai Berry Fruit Berries Cosmetic Surgeons UK Antivirus Products
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17  
Old 12-22-2008, 08:32 AM
faridam faridam is offline
Banned
 
Join Date: Dec 2008
Posts: 1
faridam is on a distinguished road
Default Re: newbie question in java

well java is a thing which require lots of practice
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18  
Old 01-07-2009, 09:13 PM
JOHN12 JOHN12 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 3
JOHN12 is on a distinguished road
Unhappy Re: newbie question in java

Quote:
Originally Posted by latchu View Post
I figured it out.. I was defining the sum/avg before num and num2 could be assigned values by the user.

import java.io.*;
import javax.swing.*;

class Numbert
{


int num , num2;

{public static void main (String[] args) throws IOException
{ String inData;

inData = JOptionPane.showInputDialog (null, "Enter an Integer Value.") ;
num = Integer.parseInt ( inData); // convert inData to int

inData = JOptionPane.showInputDialog (null, "Enter another Integer Value.");
num2 = Integer.parseInt ( inData);

int sum= num+num2;
int avg= sum/2;

System.out.println ("Sum of both numbers:" +sum);
System.out.println ("The average is:" +avg);

System.out.println ("Good-bye); //always executed
}

}
Hi,
Your coding shows some error. while initializing the variable.

Thanks

Last edited by arjkhanna : 12-02-2009 at 11:32 PM.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi Newbie here! shifanyroma Introductions 2 08-14-2009 09:43 PM
newbie pramod Introductions 2 07-08-2009 11:00 PM
Newbie here :) angel_dust Introductions 3 07-05-2009 02:13 AM
Newbie! taramichael Introductions 2 07-05-2009 01:22 AM


All times are GMT -7. The time now is 11:40 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0