Soldato
I'm learning java for fun really and am making little programs to learn from as well as books etc.
Anyway below is my little prog, user gives a number and the prog spells it out, it nearly works but not quite.
So basically it all works but.........
numbers under 10 does its bit but then carries on and does the rest of code which it shouldn't
10-19 works but then throughs up an error
20 to 99 all works fine.
It's close but i'm not sure whats the cause, if you put code in eclipse its runs or just command line and compile and run.
Thanks for any light shed on my problem.
Anyway below is my little prog, user gives a number and the prog spells it out, it nearly works but not quite.
import java.util.Scanner;
public class say {
public static String ones[] =
{
"zero" , "one" , "two" , "three" , "four", "five" , "six" , "seven" , "eight" , "nine" , "ten", "eleven",
"twelve", "thirteen", "fourteen", "fithteen" , "sixteen" , "seventeen" , "eighteen" , "nineteen" };
public static String tens[] =
{
null, "teen", "twenty" , "thirty" , "fourty", "fifty",
"sixty", "seventy", "eighty", "ninety" };
public static void main (String [] args) {
System.out.print("Enter a number between 0-99: ");
Scanner scanner = new Scanner(System.in);
String request = scanner.nextLine();
System.out.println("Thanks");{
int i = Integer.parseInt(request);
System.out.println("Your number is "+ i);
if (i < 20){
System.out.print("Your number is " + ones);}
// need it to stop here ^^^ when under 20
else if (i > 19)
i = i / 10;
int j = Integer.parseInt(request);
//but it continues
System.out.print("Your number is " + tens);
j = j % 10;
if (j == 0)
System.out.print(""); //whats a better way of making it do nothing then print ("")
//this stops it printing twenty-zero, thirty-zero rather then just twenty etc etc
else
System.out.print("-"+ ones[j]);
}
}
}
So basically it all works but.........
numbers under 10 does its bit but then carries on and does the rest of code which it shouldn't
10-19 works but then throughs up an error
20 to 99 all works fine.
It's close but i'm not sure whats the cause, if you put code in eclipse its runs or just command line and compile and run.
Thanks for any light shed on my problem.