diff --git a/C++/sumofnum_without_operator/readme.md b/C++/sumofnum_without_operator/readme.md new file mode 100644 index 0000000..a27afce --- /dev/null +++ b/C++/sumofnum_without_operator/readme.md @@ -0,0 +1,5 @@ +## FIND SUM OF TWO NUMBERS WITHOUT USING ADDITION OPERATOR OR FUNCTION + +The following program has been written in ```C++``` : + +The program goes in a loop and stores the sum in one of the numbers, by using the increment operator. \ No newline at end of file diff --git a/C++/sumofno_without_operator&addfunction.cpp b/C++/sumofnum_without_operator/sumofno_without_op_add.cpp similarity index 100% rename from C++/sumofno_without_operator&addfunction.cpp rename to C++/sumofnum_without_operator/sumofno_without_op_add.cpp diff --git a/C++/swap_without_temp/readme.md b/C++/swap_without_temp/readme.md new file mode 100644 index 0000000..d52528c --- /dev/null +++ b/C++/swap_without_temp/readme.md @@ -0,0 +1,9 @@ +## SWAP TWO NUMBERS WITHOUT USING TEMPORARY VARIABLE + +The following program has been written in ```C++``` : + +The program first adds the two numbers and stores it in the first variable + +Then the numbers are subtracted and stored in the second variable + +Finally, the numbers (with the updated values) are subtracted and stored in the first variable hence successfully swapping it diff --git a/C++/swap_without_temp/swap_without_temp.cpp b/C++/swap_without_temp/swap_without_temp.cpp new file mode 100644 index 0000000..62cdb3b --- /dev/null +++ b/C++/swap_without_temp/swap_without_temp.cpp @@ -0,0 +1,15 @@ +// C++ Program to swap two numbers without using temporary variable + +#include +using namespace std; + +int main() +{ + int a = 11, b = 6; + + // Code to swap 'a' and 'b' + a = a + b; + b = a - b; + a = a - b; + cout << "After Swapping: a =" << a << ", b=" << b; +} \ No newline at end of file diff --git a/Java/Clock display/Clock.java b/Java/Clock display/Clock.java new file mode 100644 index 0000000..3aa561b --- /dev/null +++ b/Java/Clock display/Clock.java @@ -0,0 +1,121 @@ +import java.awt.BasicStroke; +import java.awt.Color; +import java.awt.Dimension; +import java.awt.EventQueue; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.time.LocalTime; +import java.time.temporal.TemporalField; +import java.util.Date; +import java.util.concurrent.TimeUnit; +import javax.swing.JFrame; +import javax.swing.JPanel; +import javax.swing.Timer; +import javax.swing.UIManager; +import javax.swing.UnsupportedLookAndFeelException; + +public class Test +{ + + public static void main(String[] args) + { + new Test(); + } + + public Test() + { + EventQueue.invokeLater(new Runnable() + { + @Override + public void run() + { + try + { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) + { + ex.printStackTrace(); + } + + JFrame frame = new JFrame("Testing"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.add(new ClockFace()); + frame.pack(); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } + }); + } + + public class ClockFace extends JPanel + { + + public ClockFace() + { + this.startClock(); + } + + @Override + public Dimension getPreferredSize() + { + return new Dimension(600, 600); + } + + @Override + protected void paintComponent(Graphics g) + { + Graphics2D g2d = (Graphics2D) g.create(); + + LocalTime now = LocalTime.now(); + int seconds = now.getSecond(); + int minutes = now.getMinute(); + int hours = now.getHour(); + + g2d.setColor(Color.BLACK); + g2d.fillRect(0, 0, 600, 600); + g2d.setColor(Color.WHITE); + g2d.translate(300, 300); + + //Drawing the hour markers + for (int i = 0; i < 12; i++) + { + + g2d.drawLine(0, -260, 0, -300); + g2d.rotate(Math.PI / 6); + + } + + g2d.rotate(seconds * Math.PI / 30); + g2d.drawLine(0, 0, 0, -290); + + g2d.rotate(2 * Math.PI - seconds * Math.PI / 30); + g2d.rotate(minutes * Math.PI / 30); + g2d.setStroke(new BasicStroke(3)); + g2d.drawLine(0, 0, 0, -250); + + g2d.rotate(2 * Math.PI - minutes * Math.PI / 30); + g2d.rotate(hours * Math.PI / 6); + g2d.setStroke(new BasicStroke(6)); + g2d.drawLine(0, 0, 0, -200); + + g2d.dispose(); + } + + public void startClock() + { + Timer timer = new Timer(500, new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + repaint(); + } + }); + timer.start(); + } + + } +} \ No newline at end of file diff --git a/Java/Clock display/readme.md b/Java/Clock display/readme.md new file mode 100644 index 0000000..795cb07 --- /dev/null +++ b/Java/Clock display/readme.md @@ -0,0 +1 @@ +This program creates a clock and displays it using java functions