answersLogoWhite

0


Best Answer

The following will sum all integers from 1-100. Adjust according to your needs.

int sum = 0;
for (int i = 1; i <= 100; i++) sum += i;
System.out.println("The sum is " + sum);

The following will sum all integers from 1-100. Adjust according to your needs.

int sum = 0;
for (int i = 1; i <= 100; i++) sum += i;
System.out.println("The sum is " + sum);

The following will sum all integers from 1-100. Adjust according to your needs.

int sum = 0;
for (int i = 1; i <= 100; i++) sum += i;
System.out.println("The sum is " + sum);

The following will sum all integers from 1-100. Adjust according to your needs.

int sum = 0;
for (int i = 1; i <= 100; i++) sum += i;
System.out.println("The sum is " + sum);

User Avatar

Wiki User

15y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

import java.io.*;

class TwoD

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the no. of Elements: ");

byte a=Byte.parseByte(in.readLine());

int ar[]=new int[a];

long sum=0;

for(byte i=0;i<a;i++)

{

System.out.print("Enter the value of ar[ "+i+" ]: ");

ar[i]=Integer.parseInt(in.readLine());

}

for(byte i=0;i<a;i++)

sum+=ar[i];

System.out.print("Sum= "+sum);

}

}

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

The following will sum all integers from 1-100. Adjust according to your needs.

int sum = 0;
for (int i = 1; i <= 100; i++) sum += i;
System.out.println("The sum is " + sum);

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

You loop through all the elements in the array. Something like this:

sum = 0;

for (i = 0; i<= myArray.length()) {

sum += myArray[i];

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java code to find the sum in all integer?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Executon steps in java?

First of all the compiler converts our source code into byte code ,this is done by "javac" compiler.then we use interpretor that is the"java interpretor" for making our byte code executed.thats y java is called as an compiled and interpred language.by that way our java program will be interpreted. First of all our source code vl b converted into byte code by da java compiler named "javac" ,then dt byte code vl be executed by da interpretor named "java" interpretor. These are execution steps in java dts y v call java as a compiled and interpreted language.


Why the java hybrid language?

I am not sure why you label it "hybrid". Java compiles the source code, not for a specific processor, but for what you might consider a fictitious processor. That is, it doesn't compile for the specific machine code understood by a real processor.As for the reason, that's because that's what Java is all about. Java programs are supposed to be compiled only once, and then run on any computer that has an appropriate Java runtime (the "Java Virtual Machine").


How can sbt be used to build java code?

First of all, you have to start SBT while having java already in the JDK7 folder. You will need to specify Java Home as a command option. This changes the java version to the same one SBT uses.


Explain the statement there is more to java than the language?

All programming languages are abstract things - collections of rules which dictate how symbols may form words, how words may form statements, and how statements may form programs. Programming languages need "other stuff" in order to actually be useful. For most languages this will include either a compiler or an interpreter which can turn source code into executable programs. Java's "other stuff" includes a compiler, which turns Java source code into Java byte code, and the Java Virtual Machine (JVM), which allows Java byte code to execute on your computer.


I am learning java next what you want me to read?

Java is an object-oriented programming language that is generally designed either to be compiled into native (machine) code or to be interpreted from source code at runtime. Java is intended to be compiled into a byte code, which is then run (generally using JIT compilation) by a Java Virtual Machine. Java training curriculum has been designed in such a way that it provides a proper understanding of Java Programming along with different features like file handling, string handling, threading, etc. Java is platform-independent and is used to develop Console Applications, Desktop Applications, and Web Applications. Java also supports multi-threading which helps it to perform multiple tasks at the same time. IT DESK promotes Java Training courses to the students to do Internships and all the Training is given on the latest version of Java. at our institutes all over India

Related questions

Executon steps in java?

First of all the compiler converts our source code into byte code ,this is done by "javac" compiler.then we use interpretor that is the"java interpretor" for making our byte code executed.thats y java is called as an compiled and interpred language.by that way our java program will be interpreted. First of all our source code vl b converted into byte code by da java compiler named "javac" ,then dt byte code vl be executed by da interpretor named "java" interpretor. These are execution steps in java dts y v call java as a compiled and interpreted language.


Do you hava different jre for every editionEESEME of the java platform like jdk does jre too has all the java libraries?

First of all, JDK is Java Development Kit and JRE is java runtime Environment. JDK provides compiler and all the necessary tools to write the code verses JRE provides with the environment in which the java code will run.


The diff between int integer?

In Java, an int is a primitive type and an Integer is a class. Basically, an Integer is just an int primitive wrapped up in a class. Mainly this is used for the generics introduced in Java 1.5. Primitive types cannot be used as generic types, so there was a need for classes to wrap around all primitive types so that you can declare things such as List&lt;Integer&gt;.


How will you convert wrapper integer into primitive integer in java?

All integeral wrapper class (Byte,Short,Integer,Long)contains the following valueOf() .public static wrappertype valueOf(String s,int radix);integer I=Integer.valueOf("1010",2);output is 10....


Why the java hybrid language?

I am not sure why you label it "hybrid". Java compiles the source code, not for a specific processor, but for what you might consider a fictitious processor. That is, it doesn't compile for the specific machine code understood by a real processor.As for the reason, that's because that's what Java is all about. Java programs are supposed to be compiled only once, and then run on any computer that has an appropriate Java runtime (the "Java Virtual Machine").


How can sbt be used to build java code?

First of all, you have to start SBT while having java already in the JDK7 folder. You will need to specify Java Home as a command option. This changes the java version to the same one SBT uses.


How do you write javascript codes for website on a mac?

You can write java script code on any platform be it mac, linux, solaris or windows. All you need is a mac version of notepad, some html page where you insert your java script code and a web browser where you view the html page. All major browsers support java script coding and all you need to do is enable the Java Script support in browsers if it is not enabled already.


What is mean by Classes and Objects?

an Object is an instance of the Class for ex: Integer i = new Integer (1); i is an object of the Class Integer. of courses classes contain variables and methods and constructors. although the Object Class is a different case, it's the main class that all the classes in java are subClasses of it


Do you need to learn Java script to be able to use it?

No. Java Script is huge and learning all of it is impossible. Just try and code the basics and later get to the harder stuff


Explain the statement there is more to java than the language?

All programming languages are abstract things - collections of rules which dictate how symbols may form words, how words may form statements, and how statements may form programs. Programming languages need "other stuff" in order to actually be useful. For most languages this will include either a compiler or an interpreter which can turn source code into executable programs. Java's "other stuff" includes a compiler, which turns Java source code into Java byte code, and the Java Virtual Machine (JVM), which allows Java byte code to execute on your computer.


Why java is plateformindepedent?

Java enabled machines (PC, Mac, Smart Phones,etc.) all have their own version of whats called the JVM (or java virtual machine). The JVM takes source code written by programmers and converts into the corresponding machine code. For example a JVM running on a PC would convert the source into machine code corresponding to a PC and so on.


What is reason that java is powerful?

Java is very powerful because: a. It is easy to learn and code b. It is object oriented c. It has a lot of features d. It is platform independent e. Almost all platforms can run java programs f. Java is free g. And so on.