Mallesham
write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string
2 Answer(s)      4 years and 3 months ago
Posted in : Java Beginners

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.

Advertisement
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










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 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
Advertisements
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
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
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
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
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 for inserting a substring in to the given main string from a given position
write a java program for inserting a substring in to the given main string from a given position  write a java program for inserting a substring in to the given main string from a given position
write a java program
write a java program  write a program to print '*' in a circular form
Determining the Number of Days in a Month
Determining the Number of Days in a Month   This section will show the way of counting the number of days of a month in the specified year. Following program takes the year as input through the keyboard and shows the number of days
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
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 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
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 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 - Java Beginners
write a program  1. write a program that reads a string composed of 6... { public static void main(String[] args) { String str = "hello abc xyz pqr ghf anm"; String strAr[] = str.split(" "); for(int i=0;i
write program - Java Beginners
write program  write a java program that will read the values... main(String[] args) { int array[][] = {{5,6,7},{4,8,9}}; int array1...]); } System.out.println(); } } } For more information on java visit to : http
Java get number of days between dates
Java get number of days between dates  ... the number of days between the two described dates. In order to get the number of days between two dates, the given example has set two dates by using
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
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
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
Java Automorphic number program - Java Beginners
Java Automorphic number program  Write a program to read a positive... void main(String args[]){ System.out.print("Enter any number :"); Scanner input=new Scanner(System.in); int n=input.nextInt(); if(d>=n
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
A program to find the sum of odd number
A program to find the sum of odd number In this section you will learn how to find the sum of odd number in the series up to the given number in java... input from the user, applying a loop which will keep on executing up
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