Java applet program to display numerical values

Display numerical values

This program shows the concept how to display numerical values.

  • In applet we cannot display integer values.
  • To display numerical value first convert them into String.
  • eg

    int a=20;
    String s=String.valueOf(a);
    
  • String values are displayed using drawString() method of graphics.

Here is the example of displaying numerical values.

Scanfcode.java

import java.util.*;
import java.awt.*;
import java.applet.*;
public class scanfcode extends Applet
{
  public void paint(Graphics g)
  {
	  int x=55,y=44,z;
     z=x+y;
     String s;	
      s="Sum of two numbers is: "+ String.valueOf(z);
	  g.drawString(s,100,100);
  }
}

scanfcode.html

<html>
<head>
<title>
<p>First applet program</p>
</title>
</head>
<body>
<applet code="scanfcode.class" width="350" height="350">
</applet>
</body>
</html>

Now enter a command in cmd.

Display numerical values

OUTPUT

Display numerical values


Comment below if you are facing any problem


Also read

Java first applet program to display WELCOME TO SCANFCODE


Summary
Java applet program to display numerical values
Article Name
Java applet program to display numerical values
Description
This program shows the concept how you can display numerical values.To display numerical value first convert them into String.
Author
Publisher Name
Scanfcode
Publisher Logo

Leave a Reply

Your email address will not be published. Required fields are marked *