Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Programm Schaltjahr2 mit if-else und logischen Verknüpfungen
- * Mario Hansen, 05.09.2017
- */
- import javax.swing.JOptionPane;
- public class Schaltjahr2 {
- public static void main(String[] args) {
- String eingabeJahr;
- double jahr, rest4, rest100, rest400;
- boolean istSchaltjahr = true;
- eingabeJahr = JOptionPane.showInputDialog("Gib eine Jahreszahl ein!");
- jahr = Double.parseDouble(eingabeJahr);
- //Bildung der Modula von Jahr
- rest4 = jahr % 4;
- rest100 = jahr % 100;
- rest400 = jahr % 400;
- //Auswahlstruktur und logische Verknüpfung
- if (rest4 == 0) {
- istSchaltjahr = true;
- } else {
- if (rest400 == 0) {
- istSchaltjahr = true;
- } else {
- if ((rest100 == 0) || (rest4 != 0)) {
- istSchaltjahr = false;
- }
- }
- }
- if (istSchaltjahr == true) {
- JOptionPane.showMessageDialog(null, jahr + " ist Schaltjahr!");
- } else {
- if (istSchaltjahr == false) {
- JOptionPane.showMessageDialog(null, jahr + " ist kein Schaltjahr!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment