Advertisement
Guest User

Exekveringsfel när man skriver in annat än 1-5

a guest
Oct 6th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. public class DemoAvFel {
  4.    public static void main(String[] args) {
  5.      int input = JOptionPage.showInputDialog("Skriv in ett tal mellan 1-5, absolut inget annat! ;)");
  6.      int divide = 0;
  7.  
  8.      switch(input)
  9.      {
  10.        case 1:
  11.          divide = 12;
  12.          break;
  13.        case 2:
  14.          divide = 24;
  15.          break;
  16.        case 3:
  17.          divide = 19;
  18.          break;
  19.        case 4:
  20.          divide = 7;
  21.          break;
  22.        case 5:
  23.          divide = 4;
  24.          break;
  25.      }
  26.  
  27.      double result = 42.0 / divide;
  28.      JOptionPane.showMessageDialog(null, String.format("Resultatet blev: %.2f", result));
  29.    }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement