write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string

Ads
 

write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string

write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string

ex:If a user enters a numbered value in a text field, like 1 or 2 or 3 or 4 the o/p should appear as 1st or 2nd or 3rd or 4th.

View Answers

January 25, 2011 at 3:47 PM

Hi Friend,

Try the following code:

public class OrdinalNumber {
        public static String ordinalNo(int value) {
                int hunRem = value % 100;
                int tenRem = value % 10;
                if (hunRem - tenRem == 10) {
                        return "th";
                }
                switch (tenRem) {
                case 1:
                        return "st";
                case 2:
                        return "nd";
                case 3:
                        return "rd";
                default:
                        return "th";
                }
        }

        public static void main(String[] args) {
                OrdinalNumber number = new OrdinalNumber();
                for (int i = 1; i <= 10; i++) {
                        String st = number.ordinalNo(i);
                        System.out.println(i + " = " + i + st);
                }
        }
}

Thanks


January 25, 2011 at 5:20 PM

Thank you

Ads









Related Tutorials/Questions & Answers:
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string    write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string ex:If a user enters
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.
Write a java program that encrypt and decrypt some string by adding or removing 2 on each character.  Write a java program that encrypt and decrypt some string by adding or removing 2 on each character. Example 1 : Please Enter
Advertisements
write a java program to print marklist of n students. input Register number, name and marks of three subjects.
write a java program to print marklist of "n " students. input Register number, name and marks of three subjects.  write a java program to print marklist of "n " students. input Register number, name and marks of three subjects
Write a program in Java to convert Decimal number into Binary number
Write a program in Java to convert Decimal number into Binary number  Hi, I have decimal number and I want to convert it to Binary. How to Write a program in Java to convert Decimal number into Binary number? Thanks
Prime number program in java
Prime number program in java In this example you will learn how to write a program to generate and check  prime number  in java. As we know prime... for loop generating prime number up to the limit number entered by user
Write a program in java...
to enter an integer number. Write a program in java to find the factorial...Write a program in java...  Hi, friends Please, can you help me? Q1: Write a program in java to simulate a calculator. Your program should take two
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
write a java program
write a java program  write a program to print '*' in a circular form
Write a program that takes the marks of user as input
Write a program that takes the marks of user as input  Write a program that takes the marks of user as input. If marks are greater then 60... not understand how to write a program like this and thank you
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
program on factorial of a given number in java
program on factorial of a given number in java  please tell me, how to write program on factorial of a given number in java
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  How do I write a program in Java, have the program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You
Magic number Java Program
Magic number Java Program  write a program that guesses what number the user is thinking of. Below is a sample transcript: Think of a number between... then calculate the number the person is thinking of by simply adding up the first number
Write java program?
Write java program?  1 11 121 1331 14641 15101051
write the java program?
write the java program?  1 11 121 1331 14641 15101051
write the java program?
write the java program?  1 11 121 1331 14641 15101051
Write java program?
Write java program?  1 11 121 1331 14641 15101051
write a program in java.
write a program in java.  arrange the natural n umber in 5x5 matrix as 21 22 23 24 25 20 7 8 9 10 19 6 1 2 11 18 5 4 3 12 17 16 15 14 13 i...; public class NumberSpiral{ public static void main(String[] args) { int n=5
Write a java program that prints out the following menu???
Write a java program that prints out the following menu???  Write a java program that prints out the following menu. Auser can interact with the menu... another input. Menu : 1. Find min between 3 numbers using (Math.min). 2. Get
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  Write program which accepts five students id,name,age,department,courses, taken and its grade. a. calculate its GPA . display all student information in ascending order
How to Write a Calculator Program in Java?
How to Write a Calculator Program in Java? In this Java Tutorial you will learn how to write a Calculator program in Java in easy steps. Calculator program..., subtraction, multiplication or division. In this example of writing program in Java
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
A Program To Reverse Words In String in Java .
A Program To Reverse Words In String in Java .  A Program To Reverse Words In String in Java :- For Example :- Input:- Computer Software Output :- Software Computer
java string vowel program
java string vowel program  java string vowel program   Please visit the following links: Display the word that begins with vowel Java Count Vowels
Java get number of Days in Month
Java get number of Days in Month       In this section, you will learn how to obtain the number.... Here we are going to get the number of days in the month February. Here
Factorial Program in Java
Factorial program in Java helps programmer to write factors of any given... execution of the program. BufferReader is defined under the Java I/O package.... InputStreamReader reads the input from user and then keep it into a buffer. As Java reads
I am writing a program which converts a string to a timestamp and add days to it
I am writing a program which converts a string to a timestamp and add days...:34:39"); long l=ts2.getTime() +(100060602424);//add 24 days Date d=new Date(l...=ts2.getTime() +(100060602424);//add 25 days Date d=new Date(l+10006060247

Ads