Guest User

Untitled

a guest
Feb 11th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.69 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class GemiddeldeNeerslag {
  5.  
  6.     public static void main(String[] args) {
  7.         System.out.println(new GemiddeldeNeerslag().calculateAverage());
  8.     }
  9.    
  10.     private int[] neerslagarray = new int[12];
  11.    
  12.     public double calculateAverage() {
  13.         int totaal = 0;
  14.         for(int neerslag: neerslagarray) {
  15.             totaal += neerslag;
  16.         }
  17.         return (double)(totaal)/12;
  18.     }
  19.    
  20.     public GemiddeldeNeerslag() {
  21.         Scanner scanner = new Scanner(System.in);
  22.         for(int i = 0; i < 12; i++) {
  23.             System.out.println("Geef de neerslag in voor maand " + (i + 1) + ":");
  24.             int neerslag = scanner.nextInt();
  25.             if(neerslag < 0)
  26.                 i--;
  27.             else
  28.                 neerslagarray[i] = neerslag;
  29.         }
  30.         scanner.close();
  31.     }
  32. }
  33.  
  34.  
  35. import java.util.Scanner;
  36.  
  37.  
  38. public class CamelCase {
  39.    
  40.     public static void main(String[] args) {
  41.         new CamelCase();
  42.     }
  43.    
  44.     public CamelCase() {
  45.         Scanner scanner = new Scanner(System.in);
  46.         String input;
  47.         System.out.println("Geef invoer");
  48.         while(!(input = scanner.next()).equals("STOP")) {
  49.             if(isUppercase(input.charAt(0))) {
  50.                 System.out.println("Hoofdletter");
  51.             } else {
  52.                 System.out.println("Kleine letter");
  53.             }
  54.         }
  55.         scanner.close();
  56.     }
  57.    
  58.     private static boolean isUppercase(char ch) {
  59.         return (ch <= 'Z' && ch >= 'A');
  60.     }
  61. }
  62.  
  63.  
  64. import java.util.HashMap;
  65. import java.util.Scanner;
  66.  
  67.  
  68. public class KleurCode {
  69.  
  70.     public static HashMap<Character,Integer> map = new HashMap<Character,Integer>();
  71.    
  72.     public static void loadConstants() {
  73.         map.put('z',0);
  74.         map.put('b',1);
  75.         map.put('r',2);
  76.         map.put('o',3);
  77.         map.put('g',4);
  78.         map.put('G',5);
  79.         map.put('B',6);
  80.         map.put('V',7);
  81.         map.put('L',8);
  82.         map.put('W',9);
  83.     }
  84.    
  85.     /**
  86.      * @param args
  87.      */
  88.     public static void main(String[] args) {
  89.         loadConstants();
  90.         Scanner scanner = new Scanner(System.in);
  91.         String input;
  92.         System.out.println("Geef invoer plz");
  93.         while((input = scanner.next()).length() != 3 || invalidCode(input)) {
  94.             System.out.println("Maak dat invoer 3 karakters lang is plz, geef opnieuw in plz");
  95.         }
  96.         scanner.close();
  97.         System.out.println(new KleurCode(input.toCharArray()).getResistance());
  98.     }
  99.    
  100.     public static boolean invalidCode(String s) {
  101.         for(char ch: s.toCharArray()) {
  102.             if(map.get(ch) == null)
  103.                 return true;
  104.         }
  105.         return false;
  106.     }
  107.    
  108.     public KleurCode(char[] values) {
  109.         this.a = map.get(values[0]);
  110.         this.b = map.get(values[1]);
  111.         this.c = map.get(values[2]);
  112.     }
  113.    
  114.     public KleurCode(int a, int b, int c) {
  115.         this.a = a;
  116.         this.b = b;
  117.         this.c = c;
  118.     }
  119.    
  120.     public KleurCode(int[] values) {
  121.         a = values[0];
  122.         b = values[1];
  123.         c = values[2];
  124.     }
  125.    
  126.     private int a;
  127.     private int b;
  128.     private int c;
  129.    
  130.     public int getResistance() {
  131.         return (a * 10 + b) * (int)Math.pow(10, c);
  132.     }
  133.  
  134. }
  135.  
  136.  
  137. import java.util.Scanner;
  138.  
  139.  
  140. public class Punten {
  141.  
  142.     public static final int SIZE = 20;
  143.    
  144.     public static void main(String[] args) {
  145.         Punten punten = new Punten();
  146.         punten.printInfo();
  147.     }
  148.    
  149.     public void printInfo() {
  150.         System.out.println("A's " + a + " B's " + b + " C's " + c + " Min :" + min + " Max: " + max);
  151.     }
  152.    
  153.     private int a = 0;
  154.     private int b = 0;
  155.     private int c = 0;
  156.    
  157.     private int max = Integer.MIN_VALUE;
  158.     private int min = Integer.MAX_VALUE;
  159.    
  160.     public Punten() {
  161.         Scanner scanner = new Scanner(System.in);
  162.         for(int i = 0; i < punten.length; i++) {
  163.             int resultaat = scanner.nextInt();
  164.             if(resultaat < 0) {
  165.                 i--;
  166.                 continue;
  167.             }
  168.             if(resultaat >= 12)
  169.                 a++;
  170.             else if(resultaat >= 10)
  171.                 b++;
  172.             else
  173.                 c++;
  174.             if(resultaat > max)
  175.                 max = resultaat;
  176.             else if(resultaat < min)
  177.                 min = resultaat;
  178.             punten[i] = resultaat;
  179.         }
  180.         scanner.close();
  181.     }
  182.    
  183.     private int[] punten = new int[SIZE];
  184. }
Add Comment
Please, Sign In to add comment