Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. package Ue3;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Jahreszeit {
  6.  
  7. public static String jahreszeitBestimmung (){
  8. int tag = 0;
  9. int monat = 0;
  10. String jahreszeit="test";
  11. boolean kombi=true;
  12.  
  13. do{
  14. while(tag==0){
  15. Scanner z = new Scanner(System.in);
  16. System.out.print("Tag eingeben (1-31): ");
  17.  
  18. if(z.hasNextInt()){
  19. tag=z.nextInt();
  20. }
  21. else {
  22. System.out.println("Keine ganze Zahl. Bitte Nochmal");
  23. }
  24. if(tag<1||tag>31){
  25. System.out.println("Bitte im Bereich [1-31]! Nochmal.");
  26. tag=0;
  27. }
  28. }
  29.  
  30. while(monat==0){
  31. Scanner y = new Scanner(System.in);
  32. System.out.print("Monat eingeben (1-12): ");
  33.  
  34. if(y.hasNextInt()){
  35. monat=y.nextInt();
  36. }
  37. else {
  38. System.out.println("Keine ganze Zahl. Bitte Nochmal");
  39. }
  40. if(monat<1||monat>12){
  41. System.out.println("Bitte im Bereich [1-12]! Nochmal.");
  42. monat=0;
  43. }
  44. }
  45. if(monat==1&&tag>31||monat==2&&tag>29||monat==3&&tag>31||monat==4&&tag>30||monat==5&&tag>31||monat==6&&tag>30||monat==7&&tag>31||monat==8&&tag>31||monat==9&&tag>30||monat==10&&tag>31||monat==11&&tag>30||monat==12&&tag>31){
  46. System.out.println("Ungültiges Datum. Nochmal.");
  47. kombi=false;
  48. }
  49. }while(kombi==false);
  50.  
  51. if(monat==12&&tag==21||monat==1&&tag<=31||monat==2&&tag<=29||monat==3&&tag<20){
  52. jahreszeit="Winter";
  53. }
  54. if(monat==3&&tag>=20||monat==4&&tag<=30||monat==5&&tag<=31||monat==6&&tag<20){
  55. jahreszeit="Frühling";
  56. }
  57. if(monat==6&&tag>=21||monat==7&&tag<=31||monat==8&&tag<=31||monat==9&&tag<21){
  58. jahreszeit="Sommer";
  59. }
  60. if(monat==9&&tag>=21||monat==10&&tag<=31||monat==11&&tag<=30||monat==12&&tag<20){
  61. jahreszeit="Herbst";
  62. }
  63.  
  64. return jahreszeit;
  65.  
  66. }
  67.  
  68. public static void main(String[] args) {
  69.  
  70. //while(true){
  71. System.out.println(jahreszeitBestimmung());//}
  72. }
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement