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

 
 


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)      2 years and 4 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.

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 Pages:
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
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
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
Adding an Input Map to a Component
Adding an Input Map to a Component       In this section, you will learn about the input map. Input map is used to perform actions according to the key strokes
input output
you will learn how to write java program to read file line by line. We will use...; Introduction The Java I/O means Java Input/Output and is a part... by the ObjectStreamException during a write operating. Read Text from Standard IO: Java
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 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
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 following program
-threading. Explain with examples Q2 Write a java applet that takes your name... the state transition diagram of a thread Q6 Write a java applet that displays 9...-cycle? Q10 WAP that asks the user to input 2 string. If the strings are same
Input And Output
: In the section you will learn how to write java program to read file line...; Introduction The Java I/O means Java Input/Output and is a part of java.io... from the input stream. Here is the code of the program
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
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
Dialog Box Input Loop
Prev: Example: Capitalize | Next: Java NotesDialog Box Input Loop... for empty string. Another common way for the user to indicate the end of the input...() methods both require a string, not a null, to work. Combining input
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
Write a program to calculate factorial of any given number
program to calculate factorial of any given number. First of all define a class "Factorial" under the Java I/O package. Java I/O package has a input... in java. Here is the code of program: import 
user input in java - Java Beginners
user input in java   i am trying to write a code to compute the average of 5 numbers but i dont know what to do for the program to accept user... static void main(String[] args) { double number; int count = 0
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
how to write this program
how to write this program  Write a program in java which calculates... and number of credit hours for 6 courses. The program should then calculate... or numerical grade. You will be submitting TWO versions of this program. Write one
Hi..How to Display Days by month - Java Beginners
Hi..How to Display Days by month  Hi Friend.... I have a doubt on date Program... How to display the Number of days..it should display Separate .Month by Month For Ex.. INPUT: ---------------- Year Month Day 2006 12
Problem coming up with program? Do not know where to start!
Problem coming up with program? Do not know where to start!  Write a program to simulate 1000 trials, each of which consists of tossing a fair coin 10 times and counting the number of heads. For each n = 0; : : : ; 10, your
Problem coming up with program? Do not know where to start!
Problem coming up with program? Do not know where to start!  Write a program to simulate 1000 trials, each of which consists of tossing a fair coin 10 times and counting the number of heads. For each n = 0; : : : ; 10, your
Problem coming up with program? Do not know where to start!
Problem coming up with program? Do not know where to start!  Write a program to simulate 1000 trials, each of which consists of tossing a fair coin 10 times and counting the number of heads. For each n = 0; : : : ; 10, your
Programming - Count Vowels - main
Java: Programming - Count Vowels - main Problem Write a program that reads a string and displays the number of vowels in it. This main program program... in it (length 0). Display the number of vowels in each input string by (see
input
input  a java program that will exchange the last names of two students that were input by a user
adding a dialogue
adding a dialogue  Blockquote Hi can you help with the program... { public static void main(String[] args) { Scanner input... void main(String[] args) { Scanner input=new Scanner(System.in
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
adding loop
adding loop  Hi I have a program that is not compiling when I add...:"); String p=in.nextLine(); } } And the program containing... static void main(String[] args) { Scanner input=new Scanner
Arrays
IN DECLARATIONS String[] days = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa.... String[] days = new String[] {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"}; You... by specifying a subscript or index. "Array" in Java means approximately the same
String Function Program
String Function Program  The string function program is just an application of the string manipulation functions in JAVA. The program is designed to count the number of one-letter word, two-letter word, and three-letter words
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
Console Input: Scanner
Java NotesConsole Input: Scanner The java.util.Scanner class (added in Java 5) allows simple console and file input. Of course, your program should...) { //... Initialization double n; // Holds the next input number
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 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 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
String
String  write a program using string it should replace 'c'char to integer number as 1 in whole source
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
Creating the Subscript and Superscript
Creating the Subscript and Superscript    ..., you will learn how we can create  the subscript and superscript. ... value is used for  Superscript and negative value used for subscript
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
calculation after if. user input
= aPrice * aQuantity; //calculate final cost by adding tax String fs1...; //calculate final cost by adding tax String fs2 = String.format(" your oranges... one of the following by pressing tne number on your keypad"); System.out.println
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
urgent need in two days - JSP-Servlet
="JavaScript">function isProper(string) { if (!string) return false...("Enter the contect number."); theForm.contect.focus(); return false...;<tr><td><b>Name:</b></td><td><input type
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
Primary number
Primary number  write a program to find the 100th or nth primary number?   import java.util.*; class PrimeNumber{ public static void main(String a[]) { Scanner input=new Scanner(System.in
Please write code for this program in java and Explain it ? pl'sssssssss
Please write code for this program in java and Explain it ? pl'sssssssss ...]. For example, if the input was: -80000 -79950 20 70 22 60 58 65 1950 2004... and so on and so forth. We would like to know the largest number of dinosaurs
string
string  a java program using string function to input any string...) { Scanner input=new Scanner(System.in); System.out.print("Enter string: "); String st=input.nextLine(); String str[]=st.split
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
input output
input output  java program using fileinputstream and fileoutputstream   Hi Friend, Try the following code: import java.io.*; class FileInputStreamAndFileOutputStream { public static void main(String[] args
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
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c
Write a java program that prints the decimal representation in reverse. (For example n=173,the program should print 371.)c  class rose { int n... static void main(String args[]) { System.out.println("Enter the number"+n

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.