Posts

Showing posts with the label Java Programs

Smile emoji using graphics in Java using Applet

Image
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Smile extends Applet {     public void paint(Graphics g)     {         setBackground(Color.BLACK);         g.setColor(Color.YELLOW);         g.fillOval(30,50,100, 100);         g.setColor(Color.BLACK);         g.fillOval(55,75,10, 10);         g.fillOval(95,75,10, 10);         g.drawArc(60, 85, 40,40,-30,-120);     }     } /* <applet code="Smile.class" width="200" height="200"> </applet> */ OUTPUT:

Program to find the LCM & HCF of n numbers

Image
class HcfLcm {     public static void main(String[] args)     {         int n,x;         System.out.println("Number of integers: ");          n = Integer.parseInt(System.console().readLine());          if(n<1)          {              System.out.print("Invalid input!");              System.exit(0);          }           int[] arr = new int[n];           for(int i =0; i<n; i++)           {               System.out.print("Number "+(i+1)+":");       ...

System Clock Program in Java

Image
import java.awt.*; import java.awt.event.*; import java.text.SimpleDateFormat;   import java.util.Date;   class SystemClock extends Frame { Label l,lt; void initGUI() { setTitle("System Clock"); Font font = new Font("Times New Roman", Font.PLAIN, 20); lt = new Label("Date & Time",Label.CENTER); lt.setFont(font); add(lt,BorderLayout.NORTH); l = new Label("",Label.CENTER); l.setFont(font); add(l,BorderLayout.CENTER); setSize(400,400); setVisible(true); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent w) { System.exit(0); } }); while(true) { SimpleDateFormat formatter = new SimpleDateFormat("EEE, d MMM yyyy      h:mm:ss a");       Date date = new Date();  l.setText(formatter.format(date)); } } public SystemClock() { initGUI(); } public static void main(String[] args)  { new Sy...

How to set up your computer to run java programs

Image

Program to make frequency count of words in a given text

Image
public class Frequency { public static void main(String[] args)  { String text,word; int frequency=0; System.out.println("Enter the text:"); text = System.console().readLine(); String[] t = text.split(" "); System.out.println("Enter the word which frequency count want to check:"); word = System.console().readLine(); for(int i=0;i<t.length;i++) { if(t[i].equals(word)) { frequency++; } } System.out.println("Frequency count of the word '"+word+"' is: "+frequency); } } OUTPUT: