javau3p3

import java.util.*; public class pro33 { public static void main(String ar[]) { Scanner sc=new Scanner(System.in); System.out.println("Enter how many number u want to enter"); int size=sc.nextInt(); int a[]=new int[size],i; for(i=0;i<size;i++) { a[i]=sc.nextInt(); try { if(a[i]<0) { throw new ArithmeticException("plzz enter a valid numbers"); } } catch(ArithmeticException LengthMatchException) { System.out.println(LengthMatchException.getMessage()); }} for(i=0;i<size;i++) { for(int j=i+1;j<size;j++) {if(a[i]>a[j]) { int temp; temp=a[i]; a[i]=a[j]; a[j]=temp; }} } if(size<=1) { System.out.println("lowest number is"+a[0]); } else if(a[0]==a[1]) { System.out.println("lowest number is"+a[0]); }else { System.out.println("lowest number is"+a[0]); System.out.println("second lowest number is"+a[1]); } }}

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.