K
kim988de
Gast
hallo
meine hausaufgaben lautet:
Write a program to create an array of size 25 and fill it with five digit palindromes. Print how many of the 25 are even and how many odd.
und wenn ich das ausfuehre stimmt das auch was von meinen prof verlangt wird...aber gibt es irgendwie doch eine kuerzere Loesung?
meine hausaufgaben lautet:
Write a program to create an array of size 25 and fill it with five digit palindromes. Print how many of the 25 are even and how many odd.
Code:
public class fivedigitpalindrome {
public static void main(String[] args) {
int [] anArray;
anArray = new int[25];
anArray [0]=12321;
anArray [1]=23432;
anArray [2]=34543;
anArray [3]=45654;
anArray [4]=56765;
anArray [5]=67876;
anArray [6]=78987;
anArray [7]=14741;
anArray [8]=24742;
anArray [9]=34747;
anArray [10]=47874;
anArray [11]=48984;
anArray [12]=42124;
anArray [13]=98789;
anArray [14]=87687;
anArray [15]=65456;
anArray [16]=54345;
anArray [17]=43234;
anArray [18]=32123;
anArray [19]=96369;
anArray [20]=85258;
anArray [21]=15951;
anArray [22]=95159;
anArray [23]=59495;
anArray [24]=35753;
System.out.println ("The first even number is " +anArray[1]);
System.out.println ("The second even number is " +anArray[3]);
System.out.println ("The third even number is " +anArray[5]);
System.out.println ("The fourth even number is " +anArray[8]);
System.out.println ("The fifth even number is " +anArray[10]);
System.out.println ("The sixth even number is " +anArray[11]);
System.out.println ("The seventh even number is " +anArray[12]);
System.out.println ("The eight even number is " +anArray[15]);
System.out.println ("The ninth even number is " +anArray[17]);
System.out.println ("The tenth even number is " +anArray[20]);
System.out.println ("The first odd number is " +anArray[0]);
System.out.println ("The second odd number is " +anArray[2]);
System.out.println ("The third odd number is " +anArray[4]);
System.out.println ("The fourth odd number is " +anArray[6]);
System.out.println ("The fifth odd number is " +anArray[7]);
System.out.println ("The sixth odd number is " +anArray[9]);
System.out.println ("The seventh odd number is " +anArray[13]);
System.out.println ("The eight odd number is " +anArray[14]);
System.out.println ("The ninth odd number is " +anArray[16]);
System.out.println ("The tenth odd number is " +anArray[18]);
System.out.println ("The eleventh odd number is " +anArray[19]);
System.out.println ("The twelveth odd number is " +anArray[21]);
System.out.println ("The thirteenth odd number is " +anArray[22]);
System.out.println ("The fourteenth number is " +anArray[23]);
System.out.println ("The fifteenth number is " +anArray[24]);
}
}
und wenn ich das ausfuehre stimmt das auch was von meinen prof verlangt wird...aber gibt es irgendwie doch eine kuerzere Loesung?