Program to input numbers from user using array and to calculate their Sum
Code:
OUTPUT
Enter number 1 ==> 10
Enter number 2 ==> 20
Enter number 3 ==> 30
Sum of numbers ==> 60
Code:
/**
* Program to input numbers from user using array and to calculate their Sum.
**/
import java.io.*;
public class Arry_Input
{
public static void main()throws IOException
{
try
{
int sum =0;
int ary[] = new int[3];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<3;i++)
{
System.out.print("Enter number "+(i+1)+" ==> ");
ary[i] = Integer.parseInt(br.readLine());
}
for(int i1=0; i1<3; i1++)
{
sum = sum+ ary[i1];
}
System.out.print("Sum of numbers ==> "+sum);
}
catch(Exception z)
{
System.out.println(z.toString());
}
}
}
* Program to input numbers from user using array and to calculate their Sum.
**/
import java.io.*;
public class Arry_Input
{
public static void main()throws IOException
{
try
{
int sum =0;
int ary[] = new int[3];
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i=0;i<3;i++)
{
System.out.print("Enter number "+(i+1)+" ==> ");
ary[i] = Integer.parseInt(br.readLine());
}
for(int i1=0; i1<3; i1++)
{
sum = sum+ ary[i1];
}
System.out.print("Sum of numbers ==> "+sum);
}
catch(Exception z)
{
System.out.println(z.toString());
}
}
}
OUTPUT
Enter number 1 ==> 10
Enter number 2 ==> 20
Enter number 3 ==> 30
Sum of numbers ==> 60
0 comments:
Confused? Feel free to ask
Post a Comment