mercredi 4 mars 2015

Wap in java to solve following squence [on hold]

input any numbers from keyboard and print it in word eg 150 1223 3444 = one five zero one double two three three triple four.


150 122 33444 = reads one five zero one double two double three triple four.


Rules:


Single numbers just read them separately.


2 successive numbers use double.


3 successive numbers use triple.


4 successive numbers use quadruple.


5 successive numbers use quintuple.


6 successive numbers use sextuple.


7 successive numbers use septuple.


8 successive numbers use octuple.


9 successive numbers use nonuple.


10 successive numbers use decuple.


More than 10 successive numbers read them all separately.


what i am trying



import java.util.Scanner;

public class Test {
private static Scanner sc;
private static long NUMBERS;
static long rem;
static int count = 0;
static int i = 11;
static Long a[] = new Long[i];

static long[] freq = new long[10];

public static void main(String[] args) {
long temp;

sc = new Scanner(System.in);
System.out.println("enter eleven digits");
NUMBERS = sc.nextLong();
temp = NUMBERS;


while (temp > 0) {
//calculating remainder
rem = temp % 10;

i--;

//storing each digits in array
a[i] = rem;
temp /= 10;
}

// printing values of array
for (int i = 0; i < 11; i++) {
System.out.print(" " + a[i]);

}
System.out.println();

count = 0;
/*
* in this module i am stuck go: for (int i = 1; i < 11; i++) {
*
* if(a[i-1]==a[i]) {
*
* count++;
*
* } else {tuples(count);} }
*/

// for printing corresponding values in word
for (int i = 0; i < 11; i++) {
call(a[i]);

}

}

private static void tuples(int count2) {

if (count2 == 9) {
System.out.println(" nonuple");
}

else if (count2 == 2) {
System.out.print(" double");

} else if (count2 == 3) {
System.out.print(" triple");

} else if (count2 == 4) {
System.out.print(" quadriple");

} else if (count2 == 5) {
System.out.print(" quintuple");

} else if (count2 == 6) {
System.out.print(" sixtuple");

} else if (count2 == 7) {
System.out.print(" septuple");

} else if (count2 == 8) {
System.out.print(" octabel");
}

}

private static void call(Long long1) {
if (long1 == 0) {
System.out.println(" zero");
} else if (long1 == 1) {
System.out.print(" one");
} else if (long1 == 2) {
System.out.print(" two");

} else if (long1 == 3) {
System.out.print(" three");

} else if (long1 == 4) {
System.out.print(" four");

} else if (long1 == 5) {
System.out.print(" five");

} else if (long1 == 6) {
System.out.print(" six");

} else if (long1 == 7) {
System.out.print(" seven");

} else if (long1 == 8) {
System.out.print(" eight");
} else {
System.out.print(" nine");

}

}

}

Aucun commentaire:

Enregistrer un commentaire