Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners write a program in java Adding up the subscript(st,nd,rd,th) to the number of days in a input string

Have Programming Question? Ask it here!
 
 
 


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)      3 years and 6 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 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 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
write a java program  write a program to print '*' in a circular form
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
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
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
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 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 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
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
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
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
Programming: Weeks and Days
Java NotesProgramming: Weeks and Days Name _______________________________ Write a program to read in a number of days. It should then display the number of weeks and days that that represents. You can solve this using integer
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
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
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
how to write the program - Java Beginners
how to write the program  WAP to create the report card user input... History Geography Math Phy Chem. Bio Eve CSTA Also has a back up in case of any loss of data has the feature of modifying the input data we can also
String program - Java Beginners
String program  write a program to accept a word. Pass it to the function magic(String x). The function checks the string for the presence... prints it is a magic string otherwise it prints not a magic string.  
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
Validation on input xml in java program - XML
Validation on input xml in java program  Hi.. i am accepting xml data as input which I have to use in my program. i have to validate this input xml against some schema using xml beans and NOT by using sax or dom parser. I am
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
Prime Number program in Java
Prime Number program in Java will print the prime numbers between 1 to any... program in Java: package Tutorial; public class PrimeNumber { public static void main(String[] args) { int num = 50; System.out.println("prime number
Prime Number in Java
Prime Number in Java In this Java tutorial , you will learn how to write a Java program to get prime numbers between 1 to the desired number. To start... prime number. ADS4ThUnitADS Here is the code of the java Program to get prime
how to write to file from string in Java
how to write to file from string in Java  Hi, Please any one help me for how to write to file from string in Java. I am beginner in Java... string in java? So, then visit this http://www.roseindia.net/java/examples/io
how to write this program? - Java Beginners
how to write this program?  (game:scissor,rock ,paper) A program that plays the sciccor-rock-paper game.Revise the program to let the user continuously play until either the user or the computer wins more than 4 times
Write a program to find a factorial in any given number
Write a program to find a factorial in any given number This programming tutorial will teach you how to write a factorial of any given number... number less than or equal to n. For example  4! = 4 * 3 *2 * 1
Count numbers of spaces and number of words from the input string
Count numbers of spaces and number of words from the input string Java... the string into string array using split() method and determines the number...: Java is a programming language. Number of spaces :4
Adding pop up menu on headlines.
Adding pop up menu on Headlines Here you will learn sticking a pop up menu... on to pop up menu, it opens the list of the menu automatically. For generating the pop-up menu, you will have to code a scripting language, JavaScript
write a program
write a program  write a program add 2 no.s without use arithmetic,unary operaters in java
Java Write To File From String
Java Write To File From String In this tutorial you will learn how to write to file from string. Write to file from string using java at first we will have... to execute a java program write simply on command prompt as : javac
Advertisements
 

 

 

DMCA.com