Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.34 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javaapplication9;
  7. import java.util.Scanner;
  8. /**
  9.  *
  10.  * @author salte02
  11.  */
  12. public class JavaApplication9 {
  13.  
  14.     /**
  15.      * @param args the command line arguments
  16.      */
  17.     public static void main(String[] args) {
  18.           Scanner input = new Scanner(System.in);
  19.          
  20.           int val;
  21.           boolean fortsätt = true;
  22.           double radie = 0,
  23.                  längd = 0,
  24.                  bredd = 0,
  25.                  höjd  = 0,
  26.                  volym = 0;
  27.          
  28.           final double PI = 3.14159;
  29.          
  30.          
  31.           do {
  32.              System.out.println("MENY");
  33.              System.out.println("1. Klot");
  34.              System.out.println("2. Rätblock");
  35.              System.out.println("3. Cylinder");
  36.              System.out.println("4. Avsluta");
  37.              val = input.nextInt();
  38.              
  39.             switch(val)
  40.             {
  41.                 case 1:
  42.                     System.out.print("Ange radie: ");
  43.                     radie = input.nextDouble();
  44.                     volym = 4 * PI * radie * radie * radie / 3;
  45.                     break;
  46.                 case 2:
  47.                      System.out.print("Ange radie: ");
  48.                      längd = input.nextDouble();
  49.                      bredd = input.nextDouble();
  50.                      höjd = input.nextDouble();
  51.                      volym = bredd * höjd * längd;
  52.                      break;
  53.                 case 3:
  54.                      System.out.print("Ange radie och höjd: ");
  55.                      radie = input.nextDouble();
  56.                      höjd = input.nextDouble();
  57.                      volym = PI * radie * radie * höjd;
  58.                      break;
  59.                 case 4:
  60.                     fortsätt = false;
  61.                     break;
  62.                    
  63.                 default:
  64.                     System.out.print("Felinmatning");
  65.                     break;
  66.             }        
  67.            
  68.             if(val == 1 || val == 2 || val == 3){
  69.                 System.out.print("Volym " + volym + "\n");
  70.             }
  71.            
  72.           } while (fortsätt);
  73.        
  74.  
  75.  
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement