pro45.java

import java.util.*; class RangeException extends Exception { public RangeException(String s) { super(s); } } public class pro45 { public static void main(String...args) { Scanner sc=new Scanner(System.in); double sum=0; double avg; int count=0; double sub[]=new double[5]; System.out.println("Enter 5 subject marks between 0 to 100"); for(int i=0;i<5;i++) { try { sub[i]=sc.nextInt(); if(sub[i]>100||sub[i]<0){ throw new RangeException("Enter between 0 to 100");} else { sum=sum+sub[i]; count++; } } catch( RangeException e) { System.out.println(e.getMessage()); } } System.out.println("perfect values under condition "+count); System.out.println("sum is "+sum); avg=(sum/count); System.out.println("avg is "+avg); } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.