Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class HelloWorld
- {
- public static void main(final String...args)
- {
- Scanner scanner = new Scanner(System.in);
- System.out.println("What was your name again? ");
- String name = scanner.next();
- System.out.println("Hey Ray, can you give me a random number > 0? ");
- int randomNum = 0;
- Random random = new Random();
- int tries = 0;
- while(randomNum <= 0)
- {
- String number = scanner.next();
- try
- {
- randomNum = Integer.parseInt(number);
- if(randomNum <= 0)
- {
- throw new NumberFormatException("I wanted a number > 0...");
- }
- }
- catch (NumberFormatException e)
- {
- tries++;
- System.out.println("That was not a number, please try again... ");
- if(tries >= 10)
- {
- randomNum = random.nextInt(10);
- System.out.println("Okay since you don't know what a number is, let's continue with: " + randomNum);
- }
- }
- }
- Date date = new Date(); // given date
- Calendar calendar = GregorianCalendar.getInstance(); // creates a new calendar instance
- calendar.setTime(date); // assigns calendar to given date
- int hour = calendar.get(Calendar.HOUR_OF_DAY);
- System.out.println("It's around: " + hour + " o'clock");
- int betterRandomNumer = hour * randomNum * random.nextInt(10);
- System.out.println("Our special number turned out to be: " + betterRandomNumer);
- if(betterRandomNumer > 100)
- {
- System.out.println("This is just too big, we will cut it down");
- randomNum = randomNum/(randomNum * random.nextInt(10));
- System.out.println("Our new special number turned out to be: " + betterRandomNumer + " way better!");
- }
- for(int i = 0; i < betterRandomNumer; i++)
- {
- switch(lastDigit(i))
- {
- case 1:
- System.out.println("Hello World");
- break;
- case 2:
- System.out.println("Hallo Welt");
- break;
- case 3:
- System.out.println("Oi Mundo");
- break;
- case 4:
- System.out.println("Olá Mundo");
- break;
- case 5:
- System.out.println("Salute Monde");
- break;
- default:
- System.out.println("Oh no, I'm out of languages, this will be ugly!");
- }
- }
- }
- public static int lastDigit(int number) { return number % 10; }
- }
- Output:
- What was your name again?
- Ray
- Hey Ray, can you give me a random number > 0?
- Hi
- That was not a number, please try again...
- Oh sorry
- That was not a number, please try again...
- That was not a number, please try again...
- 110
- It's around: 14 o'clock
- Our special number turned out to be: 9240
- This is just too big, we will cut it down
- Our new special number turned out to be: 16 way better!
- Oh no, I'm out of languages, this will be ugly!
- Hello World
- Hallo Welt
- Oi Mundo
- Olá Mundo
- Salute Monde
- Oh no, I'm out of languages, this will be ugly!
- Oh no, I'm out of languages, this will be ugly!
- Oh no, I'm out of languages, this will be ugly!
- Oh no, I'm out of languages, this will be ugly!
- Oh no, I'm out of languages, this will be ugly!
- Hello World
- Hallo Welt
- Oi Mundo
- Olá Mundo
- Salute Monde
Advertisement
Add Comment
Please, Sign In to add comment