package whileLoops; import java.util.Scanner; public class SumOfDigits { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int temp = n; int sum = 0; while(temp >0) { int lastDigit = temp%10; temp /= 10; sum += lastDigit; System.out.println(" Last Digit " + lastDigit + " temp " + temp + " Sum " + sum); } System.out.println("The sum of all digit of " + n + " is " + sum); } }
package arrays; import java.util.Scanner; public class AverageMarksOfStudents { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number ofstudents : "); int n = sc.nextInt(); int[] marks = new int [n]; for(int i = 0; i<n ; i++) { marks [i] = sc.nextInt(); } int averageMarks = 0; for(int i = 0; i<n ; i++) { averageMarks += marks[i]; } averageMarks /= n; System.out.println("The average marks of students are "+ averageMarks); } }
Comments
Post a Comment