473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

using arrays

create a class called Findsum
using arrays and the scanner.
store numbers into the array and use a method called find_sum(int [] arrayNumbers), that takes the array as an argument and return the total/sum of array elements
Aug 10 '15 #1
5 1510
chaarmann
785 Expert 512MB
OOOps ... You just copied your assignment.
So where is your problem?
Can you tell us what you have done so far (list code here) and where you are stuck?
Aug 10 '15 #2
I copied as it is because it was one the question i was asked by my lecturer
am just new in the course and am bit struggling.........
Aug 10 '15 #3
chaarmann
785 Expert 512MB
No problem Onalenna, everyone was a beginner once.
I hope you read the forum guidelines and knew from it that we do not do your homework for you, else you do not learn. And learning you want, else you would not do the course. And you can only learn by trying yourself and discuss your upcoming problems with others. So tell us what specific is it that you are struggling with. Show us what you have done so far.
Aug 11 '15 #4
word taken and got into consideration and thank you very much too much appreciating it so here i tried the code but am not sure that is okay according to the question above..



Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner in=new Scanner (System.in);
  7.         int num[]=new int[5];
  8.         int i=0;
  9.         int sum=0;
  10.  
  11.         for (i=0;i<num.length;i++) {
  12.             System.out.println("enter a number");
  13.             num[i]=in.nextInt();
  14.             sum=sum+num[i];
  15.         }
  16.         System.out.println("Total="+sum);
  17.     }
  18. }
Aug 13 '15 #5
chaarmann
785 Expert 512MB
Hi Onalenna,
the program looks promising. But you did 2 task in your for-loop in each step. First task: you scan in the integer (line 13) and second task: you build the sum (line 14).

So you should separate the tasks and use 2 for-loops. One for the first task, and one for the second task. You can do that by copying the whole loop (line 11 to 15) and place the copy right below the end of the loop. Then delete the second task (sum) from the first for-loop. Then delete the first task from the second copied loop.

So, now that you have the 2 tasks separated, you can just put the second loop into its own method easily, as described in your assignment. If you are using Eclipse, it will do it for you automatically by marking the second loop as selected, then right-click --> refactor --> extract method.

And if you want to become professional, then you can clean-up a bit and replace the second loop with a newer for-each loop
Aug 14 '15 #6

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

Similar topics

16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
0
by: antique | last post by:
iam supposed to CREATE A FUNCTION INT ADJUSTEDSUM (INT,INT) 1. find the sum of the array of size 100 2. find the number of occurrence of a MIN and MAX number if its twice or more only use 1...
1
by: sachin10 | last post by:
hi i m sachin, i m new to VB programming.i face some problem regarding the sorting of text file contents using arrays.text file have data in the format as below seq...
7
sammyboy78
by: sammyboy78 | last post by:
I was wondering about the format of calling methods using arrays. I know that to call a method when not using arrays it would be formatted in the first class like: public void methodName(...
3
Blackout
by: Blackout | last post by:
Hi, I'm new to C and need to make a program that displays the output of the first six powers of 2 like this: 1 2 4 8 16 32 (2 to the power of 0, 2 to the power of 1, 2 to...
16
by: mike3 | last post by:
(I'm xposting this to both comp.lang.c++ and comp.os.ms- windows.programmer.win32 since there's Windows material in here as well as questions related to standard C++. Not sure how that'd go over...
2
by: theblissfulwizard | last post by:
FYI - New to ASP I'm trying to get multiple values from checkboxes inserted into a table using arrays. I'm using VBscript - ASP 1.1 (not 2.0) and here is what I want to do. I have a page that...
1
by: James Brown | last post by:
Hi, I'm fairly new to VBA and was looking to start using arrays to calculate medians of monte carlo simulations. I know how to set up an array as I have been reading through such websites as: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.