Write a Java program to find the sum of given number 10 20 and 30. - Codeprg

Breaking

programing News Travel Computer Engineering Science Blogging Earning

Saturday, 9 May 2020

Write a Java program to find the sum of given number 10 20 and 30.


Write a Java program to find the sum of given number 10 20 and 30.
//With direct Assiging the value to variable 
class SumOfElement{

   public static void main(String args[]){
      int a=10, b=20, c=30;
      int sum = 0;
      sum=a+b+c;
    
      System.out.println("Sum of elements is:"+sum);
   }
}

//With  taking  user Input 

class SumOfElement{

public static void main(String args[])
      {

      Scanner it =new Scanner(System.in);
     System.out.println("Enter 1st elements ");
      int a=it.nextInt();
     System.out.println("Enter 2st elements ");.
      int b=it.nextInt();
    System.out.println("Enter 3st elements ");.
      int c=it.nextInt();
      int sum = 0;
      sum=a+b+c;
    
      System.out.println("Sum of elements is:"+sum);
   }
}