Skip to main content

Posts

Showing posts from October, 2023

Sum of Natural Number in java programm

 Here we provide the sum of natural number in java program code. import java . util . * ; public class sumofNaturalno {     public static void main ( String [] args ) {         Scanner sc = new Scanner ( System . in );         System . out . println ( "Enter the Naturl No: " );         int n = sc . nextInt ();         int sum = 0 ;         for ( int i = 1 ; i <= n ; i ++ ){             sum += i ;         }         System . out . println ( "The sum of first N natural no is: " + sum );     } }

Calculator In Java Language

Java Swing is a GUI (graphical user Interface) widget toolkit for Java. Java Swing is a part of Oracle’s Java foundation classes . Java Swing is an API for providing graphical user interface elements to Java Programs.Swing was created to provide more powerful and flexible components than Java AWT (Abstract Window Toolkit). In this article we will use Java Swing components to create a simple calculator with only +, -, /, * operations. add(Component c) : adds component to container. addActionListenerListener(ActionListener d) : add actionListener for specified component setBackground(Color c) : sets the background color of the specified container setSize(int a, int b) : sets the size of container to specified dimensions. setText(String s) : sets the text of the label to s. getText() : returns the text of the label. Java program to create a simple calculator with basic +, -, /, * using java swing elements.  import javax.swing.*; import java.awt.event.*; import java.awt.*; public class...