programme: To input five numbers in array and add all of it.
import java.util.*;
public class testarray
{
public static void main(String args[])
{
int x[];
x=new int[5];
int i,temp=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the five number");
for(i=0;i<5;i++)
{
x[i]=sc.nextInt();
}
System.out.println("value in array");
for(i=0;i<5;i++)
{
System.out.println(x[i]);
temp=temp+x[i];
}
System.out.println("temp="+(temp));
}
}
In this programme we further a temporary file called temp for adding all the array numbers
To run it:
save it by testarray.java
1) javac testarray.java
2) java testarray
then give 5 numbers and we got array numbers and sum.
MENTOR: ANIL KUMAR
import java.util.*;
public class testarray
{
public static void main(String args[])
{
int x[];
x=new int[5];
int i,temp=0;
Scanner sc=new Scanner(System.in);
System.out.println("enter the five number");
for(i=0;i<5;i++)
{
x[i]=sc.nextInt();
}
System.out.println("value in array");
for(i=0;i<5;i++)
{
System.out.println(x[i]);
temp=temp+x[i];
}
System.out.println("temp="+(temp));
}
}
In this programme we further a temporary file called temp for adding all the array numbers
To run it:
save it by testarray.java
1) javac testarray.java
2) java testarray
then give 5 numbers and we got array numbers and sum.
MENTOR: ANIL KUMAR
No comments:
Post a Comment