diff options
| author | Carlos Maiolino <[email protected]> | 2025-07-10 22:55:07 +0200 |
|---|---|---|
| committer | Carlos Maiolino <[email protected]> | 2025-07-10 22:56:55 +0200 |
| commit | d98f46ce647846b0aa30b2e16a30fd4e152a1bf5 (patch) | |
| tree | 267474fcc77cf20b428f6f4c7f768ca09f4cfe0e /java/atividades/loop_while.java | |
| parent | 869e68986aa8f69af6e7842260a68d1e5c6f796f (diff) | |
Add new code
Signed-off-by: Carlos Maiolino <[email protected]>
Diffstat (limited to 'java/atividades/loop_while.java')
| -rw-r--r-- | java/atividades/loop_while.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/java/atividades/loop_while.java b/java/atividades/loop_while.java new file mode 100644 index 0000000..cc7f2e7 --- /dev/null +++ b/java/atividades/loop_while.java @@ -0,0 +1,51 @@ +import javax.swing.*; + +class loop_while +{ + public static void main(String args[]) + { + int Tabuada; + char op = 0; + String msg = "", msgEntr = "1: For - 2: While - 3: do_while\n"; + + Tabuada = Integer.parseInt(JOptionPane.showInputDialog("Numero inteiro:")); + op = (JOptionPane.showInputDialog(msgEntr)).charAt(0); + + switch(op) { + case '1': { + msg = msg + "Tabuada do " + Tabuada + " pelo for: \n\n"; + for (int i=1; i<=10; i++) { + msg = msg + Tabuada + " x " + i + " = " + + Tabuada*i + "\n"; + } + break; + } + case '2': { + msg = msg + "Tabuada do " + Tabuada + " pelo while: \n\n"; + int i = 1; + while (i <= 10) { + msg = msg + Tabuada + " x " + i + " = " + + Tabuada*i + "\n"; + i++; + } + break; + } + case '3': + msg = msg + "Tabuada do " + Tabuada + " pelo while: \n\n"; + int i = 1; + do { + msg = msg + Tabuada + " x " + i + " = " + + Tabuada*i + "\n"; + i++; + }while(i <= 10); + break; + default: + } + + if (op >= '1' && op <= '3') { + JOptionPane.showMessageDialog(null, msg); + } + + System.exit(0); + } +} |
