473,385 Members | 2,015 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,385 software developers and data experts.

how i print 10 number sum

public static void main(String[] args) {
Scanner toko = new Scanner(System.in);
int a =toko.nextInt();
int b =toko.nextInt();
int c =toko.nextInt();
int d =toko.nextInt();
int e =toko.nextInt();
int f =toko.nextInt();
int q =toko.nextInt();
int w =toko.nextInt();
int r =toko.nextInt();
int t =toko.nextInt();
System.out.println(a+b+c+d+e+f+q+w+r+t);
}

i must print 10 numbers sum and its correct?
Mar 13 '12 #1
2 1550
r035198x
13,262 8TB
Don't declare ten integers to take the input. Use a for loop and add the values into a previously initialized variable.
Mar 13 '12 #2
int x;
int sum = 0;
for(i=0;i<=10;i++) {
System.out.println("enter a number:";
x = toko.nextInt();
sum = sum + x;
System.out.println("total sum is:"+sum;
}
//if you want to put the total sum at the end of your 10 inputs..
//put System.out.println("total sum is:"+sum;
outside the loop statement.
//it makes the printing method of the total sum will execute after the loop.
Mar 17 '12 #3

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

Similar topics

3
by: gasturbtec | last post by:
i'm using access 2000 and have a form in which users can select reports with check boxes and click a print button to print out the selected reports. what i want to do now is place a text box on the...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
1
by: Smalley | last post by:
Need some help please. Have this code and for some reason it is not working correctly. I am not receiving errors, just the table is not being populated at all. I have created the tbl and the frm...
2
by: asit | last post by:
why this program shows ambiguous behavior ?? import os import stat import time #import types file_name=raw_input("Enter file name : ") print file_name, "information" st=os.stat(file_name)
11
by: davidj411 | last post by:
i am parsing a cell phone bill to get a list of all numbers and the total talktime spend on each number. i already have a unique list of the phone numbers. now i must go through the list of...
3
by: vileoxidation | last post by:
Hello, and thanks for any help in advance! Basically, as the title says, I am looking for a way to print the number of times the user gave the program an input, and then also print the average of...
5
by: sedaw | last post by:
why the print loop is not alright ? #include <stdio.h> void main() { int n, i, X, temp; printf("N=?\n"); scanf("%d",&n); for(i=1; i<n; i++) { temp=i;
1
by: briggs | last post by:
Hi All, I need to take the count of txt and bak files present in all the directory.for eg if we assume there are two directoies say(test1, test2), I need to collect the count(of txt and bak files)...
1
by: chungku | last post by:
#/usr/bin/perl use strict; use warnings; # Setup the counters my $shed_counter= 0; # question mark counter my $doubleshed_counter = 0; # period counter
4
by: JanineXD | last post by:
Hello, I already have the program ( convert number to words but only 0-999 ). I need it to be ( 0-9999 ). can you help me? package num2word; import java.util.Scanner;
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.