# Assigning ordinate numbers

Ads

Share on Google+

Chow ah goon
Assigning ordinate numbers
2 Answer(s)      7 years ago
Posted in : JSP-Servlet
Ads
View Answers

November 16, 2009 at 11:40 AM

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();
int i=123;
String st=number.ordinalNo(i);
System.out.println(i+st);
}
}

Thanks

November 17, 2009 at 11:14 AM

Hi Friend,

For random number:

import java.util.*;
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();
Random r=new Random();
int num=r.nextInt(100);
System.out.println(num);
String st = number.ordinalNo(num);
System.out.println( num + st);

}
}
Thanks

Ads

Related Tutorials/Questions & Answers:
Assigning ordinate numbers - JSP-Servlet
Assigning ordinate numbers  Hi all, I have a question to seek your help. How do I assign an ordinal number to a randomly generated number? For example is the generated number is 5, how do i write a code that will print
Assigning URL
Assigning URL  Actually i have created an attendance template, i can use it perfectly, now the problem is how can my team members access the attendance template without having the source file, i need to know how to assign a web
Advertisements
assigning arraylist to combo box
assigning arraylist to combo box  Hi I am busy coding the Airline Reservation program, i have an arraylist of locations which i want to assing to the combo box. please help
Assigning seats on an airplane
Assigning seats on an airplane  Hi How to write a java program (using swing classes) to assign seats on an airplane .Assume the airplane has 20 seats in first class(5 rows of 4 seats each, seperated by an aisle), and 180 seats
Assigning variable in mysql - SQL
Assigning variable in mysql  i have tables purchase, serialtable and salesdetail. i want to create a trigger that will fire on insert on salesdetails to update my purchase.quantityInstock column by selecting a productcode from
Assigning higher priority - Java Beginners
Assigning higher priority  Sir,plz help me to write a program which illustrate the 'effects of assigning higher priority to a thread'?  Hi Friend, Please visit the following link: http://www.roseindia.net/answers
Assigning value to anchor <a></a> tag using custom tag
Assigning value to anchor tag using custom tag  hi, I am trying to assign a value to anchor tag within a custom tag and redirecting the link... time. I think the problem is im assigning in custom tag . package
automorphic numbers
automorphic numbers  how to find automorphic number in java   Hi Friend, Pleas visit the following link: Automorphic numbers Thanks
sorting numbers
sorting numbers  How to sort the numbers in ascending order   import java.util.*; class SortNumbers{ public static void main(String...=input.nextInt(); list.add(num); } System.out.println("Numbers
Prime Numbers
Prime Numbers  Create a complete Java program that allows the user to enter a positive integer n, and which then creates and populates an int array with the first n prime numbers. Your program should then display the contents
Numbers pyramid
Numbers pyramid  Hi sir, Can you please tell me how to output this using nested for loops? 1 2, 1 1, 2, 3 4, 3, 2, 1 1, 2, 3, 4, 5 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7 8, 7, 6, 5, 4, 3, 2, 1 1, 2, 3, 4, 5, 6, 7, 8, 9 10, 9, 8
Rational Numbers
Rational Numbers   Write and fully test a class that represents rational numbers. A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator
Assigning a value to JSP variable from a bean class. - JSP-Servlet
Assigning a value to JSP variable from a bean class.  Hi, I want to know how we can assign value to a JSP variable from a Java Bean. I am using Struts, JSTL. Which tags should I use to assign the value. e.g Kindly
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
how to add to numbers in java
how to add to numbers in java  how to add to numbers in java
Hexadecimal numbers multiplication
Hexadecimal numbers multiplication  Sir, I have to multiply 128 bit hexadecimal numbers. Do u have any logic for this?? The numbers are like ab7564fa342b5412c34d9e67ab341b58
Addition of two numbers
Addition of two numbers  addition of two numbers
defining numbers in Java Script
defining numbers in Java Script  Explain about defining numbers in Java Script
multiply of 100 digits numbers
multiply of 100 digits numbers  multiplying 100 digits numbers to eachother
numbers divisible by 5 and 6
numbers divisible by 5 and 6  Find the first ten numbers which are greater than Long.MAX_VALUE divisible by 5 and 6
prime numbers - Java Beginners
prime numbers  Write a java program to find the prime numbers between n and m
Adding two numbers
Adding two numbers  Accepting value ffrom the keyboard and adding two numbers
Generate Random Numbers
Generate Random Numbers  hi,,, Please give me answer with example How do you generate random numbers within a given limit with actionscript... This function generate random numbers with in given limit
random numbers - Java Beginners
random numbers  write a program to accept 50 numbers and display 5 numbers randomly  Hi Friend, Try the following code: import...); System.out.println("Enter 10 numbers: "); for(int i=0;i<10;i
odd numbers with loop
odd numbers with loop  get the odd numbers till 100 with for,while loop   Java find odd numbers: class OddNumbers { public static void main(String[] args) { for(int i=1;i<=100;i
recursion numbers - Java Beginners
recursion numbers  I need to use recursion to test all values from 0 to 20 and see if they are contain in a 1-D array with values: 2,4,6,8,10,12,14,16,18,20. The results of all numbers from 0-20 will be printed
Sum of positive and negative numbers
; import java.util.*; class Numbers { public static void main(String...=0,sum2=0; int num[]=new int[10]; System.out.println("Enter 10 numbers...]; } } System.out.println("Sum of positive numbers: "+sum2); System.out.println
Application for print pyramid of numbers
Application for print pyramid of numbers  What is the code for printing the numbers like 1 1 1 1 2 2 1 1 3 4 3 1 1 4 7 7 4 1
Sum of first n numbers
Sum of first n numbers  i want a simple java program which will show the sum of first n numbers....   import java.util.*; public class...; } System.out.println("Sum of Numbers from 1 to "+n+" : "+sum
random numbers - Java Beginners
to display the random numbers, but not twice or more. I mean i need a number to be display once. This code allows some numbers to be displayed more than once. Hi... Scanner(System.in); System.out.println("Enter 10 numbers: "); for(int i=0;i<10;i

Ads

Advertisement null

Ads