hi i am practicing a program here.
reversed number
get smallest and largest numbers
get odd and even numbers
the reversed numbers is working just the way it is supposed to.
the odd and even numbers is working the way it is supposed to work. i am getting the correct output from the both of them
it is just the smallest and largest numbers is not giving me the correct output
the smallest output is giving is zero
the largest output is 3
these are the numbers that i entered: 0,10,12,205,23,100,0,5,11, from that numbers it is supposed to give the reversed numbers, odd and even number and also the smallest and largest.
any help would be greatly appreciated on how to get the correct output from the smallest and largest. here is the codes that i used.
these are just simple program that i am using as practice.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | int arr[]= new int [ 10 ]; int i= 0 ; int largest= 0 , smallest = 0 ,num; for (i= 0 ; i<= 9 ; i++) { System.out.println( "please enter a number" ); arr[i] = userinput.nextInt(); } for (i= 9 ; i>= 0 ; i--) { System.out.println(arr[i]+ "\t" ); } for (i= 1 ; i<=arr.length; i++) { if (i== 0 ) { largest = arr[i]; } else if (arr[i] > largest) { largest = arr[i]; } else if (arr[i]< smallest) { smallest = arr[i]; } System.out.println( "the smallest number is " +smallest); System.out.println( "the largest number is " + largest); for (i= 0 ; i<= 9 ; i++) { if (arr[i]% 2 == 0 ) { System.out.println(arr[i]+ " even number" ); } else if (arr[i]% 2 != 0 ) { System.out.println(arr[i]+ " odd number" ); } } |