Improving my program

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1480 Views - Last Post: 18 August 2012 - 06:10 AM Rate Topic: -----

#16 cfoley   User is offline

  • Cabbage
  • member icon

Reputation: 2425
  • View blog
  • Posts: 5,068
  • Joined: 11-December 07

Re: Improving my program

Posted 17 August 2012 - 07:10 AM

It's just practice. The length of a program is not always the best thing to judge it by. However, in this case, I would find it hard to justify going over a hundred lines. After all, you could just do this: (generated by code, before anyone asks!)

	public static String convert(int n) {
		if (n == 0) return "zero";
		if (n == 1) return "one";
		if (n == 2) return "two";
		if (n == 3) return "three";
		if (n == 4) return "four";
		if (n == 5) return "five";
		if (n == 6) return "six";
		if (n == 7) return "seven";
		if (n == 8) return "eight";
		if (n == 9) return "nine";
		if (n == 10) return "ten";
		if (n == 11) return "eleven";
		if (n == 12) return "twelve";
		if (n == 13) return "thirteen";
		if (n == 14) return "fourteen";
		if (n == 15) return "fifteen";
		if (n == 16) return "sixteen";
		if (n == 17) return "seventeen";
		if (n == 18) return "eighteen";
		if (n == 19) return "nineteen";
		if (n == 20) return "twenty";
		if (n == 21) return "twenty-one";
		if (n == 22) return "twenty-two";
		if (n == 23) return "twenty-three";
		if (n == 24) return "twenty-four";
		if (n == 25) return "twenty-five";
		if (n == 26) return "twenty-six";
		if (n == 27) return "twenty-seven";
		if (n == 28) return "twenty-eight";
		if (n == 29) return "twenty-nine";
		if (n == 30) return "thirty";
		if (n == 31) return "thirty-one";
		if (n == 32) return "thirty-two";
		if (n == 33) return "thirty-three";
		if (n == 34) return "thirty-four";
		if (n == 35) return "thirty-five";
		if (n == 36) return "thirty-six";
		if (n == 37) return "thirty-seven";
		if (n == 38) return "thirty-eight";
		if (n == 39) return "thirty-nine";
		if (n == 40) return "forty";
		if (n == 41) return "forty-one";
		if (n == 42) return "forty-two";
		if (n == 43) return "forty-three";
		if (n == 44) return "forty-four";
		if (n == 45) return "forty-five";
		if (n == 46) return "forty-six";
		if (n == 47) return "forty-seven";
		if (n == 48) return "forty-eight";
		if (n == 49) return "forty-nine";
		if (n == 50) return "fifty";
		if (n == 51) return "fifty-one";
		if (n == 52) return "fifty-two";
		if (n == 53) return "fifty-three";
		if (n == 54) return "fifty-four";
		if (n == 55) return "fifty-five";
		if (n == 56) return "fifty-six";
		if (n == 57) return "fifty-seven";
		if (n == 58) return "fifty-eight";
		if (n == 59) return "fifty-nine";
		if (n == 60) return "sixty";
		if (n == 61) return "sixty-one";
		if (n == 62) return "sixty-two";
		if (n == 63) return "sixty-three";
		if (n == 64) return "sixty-four";
		if (n == 65) return "sixty-five";
		if (n == 66) return "sixty-six";
		if (n == 67) return "sixty-seven";
		if (n == 68) return "sixty-eight";
		if (n == 69) return "sixty-nine";
		if (n == 70) return "seventy";
		if (n == 71) return "seventy-one";
		if (n == 72) return "seventy-two";
		if (n == 73) return "seventy-three";
		if (n == 74) return "seventy-four";
		if (n == 75) return "seventy-five";
		if (n == 76) return "seventy-six";
		if (n == 77) return "seventy-seven";
		if (n == 78) return "seventy-eight";
		if (n == 79) return "seventy-nine";
		if (n == 80) return "eighty";
		if (n == 81) return "eighty-one";
		if (n == 82) return "eighty-two";
		if (n == 83) return "eighty-three";
		if (n == 84) return "eighty-four";
		if (n == 85) return "eighty-five";
		if (n == 86) return "eighty-six";
		if (n == 87) return "eighty-seven";
		if (n == 88) return "eighty-eight";
		if (n == 89) return "eighty-nine";
		if (n == 90) return "ninety";
		if (n == 91) return "ninety-one";
		if (n == 92) return "ninety-two";
		if (n == 93) return "ninety-three";
		if (n == 94) return "ninety-four";
		if (n == 95) return "ninety-five";
		if (n == 96) return "ninety-six";
		if (n == 97) return "ninety-seven";
		if (n == 98) return "ninety-eight";
		if (n == 99) return "ninety-nine";
		throw new IllegalArgumentException(n + " is not in the range 0-99");
	}


Was This Post Helpful? 0
  • +
  • -

#17 HopelessDev   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 136
  • Joined: 10-August 12

Re: Improving my program

Posted 18 August 2012 - 05:48 AM

@baavagai! Thank you so much! I'll keep in mind everything that you said!

We just finished our preliminary exam so I'm back on working with the code. I understood casio's way now and I'm amazed with what he did :D I'm trying to solve the exercise differently from casio's style. My program logic restricted me to 999k. lol
Was This Post Helpful? 0
  • +
  • -

#18 CasiOo   User is offline

  • D.I.C Lover
  • member icon

Reputation: 1578
  • View blog
  • Posts: 3,551
  • Joined: 05-April 11

Re: Improving my program

Posted 18 August 2012 - 06:10 AM

View PostHopelessDev, on 18 August 2012 - 12:48 PM, said:

@baavagai! Thank you so much! I'll keep in mind everything that you said!

We just finished our preliminary exam so I'm back on working with the code. I understood casio's way now and I'm amazed with what he did :D I'm trying to solve the exercise differently from casio's style. My program logic restricted me to 999k. lol


Thank you :)

There sure must be many possible solutions, and I bet mine isn't the best ^^ Though it is working and can easily be expanded to quintillion
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2