source file name: expdemo3.java class expdemo3 { public static void main (String args[]) { expdemo3 ob= new expdemo3(); double avg=ob.average(args); System.out.println("average of "+args.length+" number is: "+avg); } public double average (String as[]) { double sum =0.0 ; try { for( int i=0;i<…
Read more4) Write a Java program to find sum of command line numbers and count the Invalid integers entered.
source file name: expdemo.java class expdemo { public static void main (String as[]) { int n, cnt=0, sum=0; for(int i=0;i<as.length;i++) { try { n=Integer.parseInt(as[i]); sum= sum+n; } catch (NumberFormatException e) { //system.out.println("invalid integer:"); cnt++; } } System.out.println("Sum of…
Read moreclass exceptiondemo1 { public static void main(String as[]) { System.out.println("exception handling program"); int a,b,add,sub,mul,div; try { a=Integer.parseInt(as[0]); b=Integer.parseInt(as[1]); add=a+b; sub=a-b; mul=a*b; div=a/b; System.out.println("add: "+add+&…
Read more2) Write a java Program that generates a custom or user defined exception if any of its command line arguments are negative.
class NegativeNumberException extends Exception { public NegativeNumberException(String s) { super(s); } } class expdemo3 { static int check(int m)throws NegativeNumberException { if(m<0)throw new NegativeNumberException("Number<0"); return m; } public static void main(Str…
Read more1) Write a Java program that finds super classes of given Class using command line.
class expdemo2 { public static void main(String ad[]) { boolean b=true; String ss[]; int i=0; try { String clsname=ad[0]; while(b) { Class f=Class.forName(clsname); Class supercls=f.getSuperclass(); if(supercls!=null) { i++; ss=supercls.toString().split(" "); System.out.…
Read more