1,105,578 Community Members

how to write superscript in core java

Member Avatar
pri.chakraborty
Newbie Poster
4 posts since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi all.. I m a begginer in java... i want to write a series like 1 to the power 2, 2 to the power 3 as so on... i can print its value only line 1 , 8 , 81...
but i cant write the series where all to the power number will be in superscript order... pls can anyone help me?? here is my code where i found only the values of 1 to the power2 , 2 to the power 3....

import java.io.*;
class srs3
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int i,n,m;
        System.out.println("Enter the range:-");
        n=Integer.parseInt(br.readLine());
        System.out.println();
        System.out.println("The series upto "+n+" is: "); 
        System.out.println();       
        for(i=1;i<=n;i++)
        {
            int s=(int) Math.pow(i,(i+1));
            System.out.print(s+" ");

        }
    }
}

thanks in advance.... :)

Member Avatar
uurcnyldrm
Light Poster
26 posts since Jan 2012
Reputation Points: -3 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
1
 

superscript in Java String

Look at the above link. It will solve your problem.

Member Avatar
radhakrishna.p
Posting Whiz in Training
281 posts since Nov 2012
Reputation Points: 29 [?]
Q&As Helped to Solve: 64 [?]
Skill Endorsements: 11 [?]
 
-1
 

we can achieve this by using AttributedString class which is available in java.text.*; package

the following url's may help you for this

http://www.java2s.com/Code/JavaAPI/java.text/TextAttributeSUPERSCRIPT.htm

http://www.daniweb.com/software-development/java/threads/186751/printing-powers-in-java

please check it once

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: