Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package thirdPdf;
- import javax.swing.*;
- import javax.swing.plaf.FontUIResource;
- import java.awt.*;
- import static javax.swing.JOptionPane.showInputDialog;
- import static javax.swing.JOptionPane.showMessageDialog;
- /**
- * Created by Kurnosova Iryna on 01.10.2017.
- */
- public class Square {
- public static void main(String[] args) {
- UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("Arial", Font.ITALIC, 15)));
- UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("Arial", Font.ITALIC, 18)));
- String inputBorder = showInputDialog(null, "Enter the last digit ", "Border digit", JOptionPane.QUESTION_MESSAGE);
- int digitBorder, result = 0;
- digitBorder = Integer.parseInt(inputBorder);
- //first variant of a loop
- /*for(int i = 1; i <= digitBorder; i++){
- result += Math.pow(i, 2.0);
- }*/
- //second variant of a loop
- int i = 1;
- while(i <= digitBorder){
- result += Math.pow(i, 2.0);
- i++;
- }
- showMessageDialog(null, result, "Square", JOptionPane.INFORMATION_MESSAGE);
- }
- }
Add Comment
Please, Sign In to add comment