Write a program to sum first n even numbers using while loop in java. ( #JAVA )
/* Question 2 : Write a program to sum first n even numbers using while loop. */
package com.company; import java.util.Scanner; public class EvenSum { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int sum=0; int n; System.out.println("Input value of n :"); n = sc.nextInt(); for(int i=0;i<n;i++){ sum = sum + (2*i); } System.out.print("Sum of even numbers is: "); System.out.println(sum); // First 4 even numbers are - 0 2 4 6 } // end of main } // end of class
Thanks Dosto for Reading this blog.
I think you all are definitely thinking of being connected with me.
ππ»Β InstagramΒ :Β https://www.instagram.com/thetechdcode/
ππ»Β Facebook PageΒ :Β https://www.facebook.com/thetechdcode
ππ»Β TwitterΒ :Β https://twitter.com/thetechdcode
ππ»Β TelegramΒ ChannelΒ :Β https://t.me/thetechdcode
ππ»Β YouTubeΒ :Β https://www.youtube.com/channel/UCjJnEdeugftBwQ3yMuD4B_A
ππ»Β Tech DCode LinktreeΒ :Β https://linktr.ee/thetechdcode
ππ»Β My Personal HandlesΒ :Β https://linktr.ee/virtualshivamin
π§βπ»π§βπ»Β Social Media Links of SHIVAM SINGH (OWNER) :
ππ»Β InstagramΒ :Β https://www.instagram.com/virtualshivamin/
ππ»Β Facebook PageΒ :Β https://www.facebook.com/virtualshivamin/
ππ»Β TwitterΒ :Β https://twitter.com/virtualshivamin/
ππ»Β Personal LinktreeΒ :Β https://linktr.ee/virtualshivamin
π€π€Β Check Best Offers/Deals and Discount on Amazon :
πΒ AmazonΒ :Β https://amzn.to/3tLt2FN
πΒ BestsellersΒ :Β https://amzn.to/31boSuB
πΒ New RealeasesΒ :Β https://amzn.to/3rdru5U
πΒ Movers and ShakersΒ :Β https://amzn.to/3lFu5nY
πΒ Computer and accessories :Β https://amzn.to/3lERTbJ
πΒ ElectronicsΒ :Β https://amzn.to/3sqHW4l
πΒ SoftwaresΒ :Β https://amzn.to/3ccwAee