This article is a ** story post ** based on what I came up with on the train. Please forgive me because it is not a written description of any technology. Then this article could be a spoiler for the movie "Spirited Away". Only people who say "OK!" Should go down.
Yubaba.java
import java.util.Scanner;
import java.util.Random;
public class Yubaba {
public static void main(String[] arts){
System.out.println("It's a contract. Write your name there.");
Scanner keiyakusho = new Scanner(System.in);
String name = keiyakusho.nextLine();
System.out.println("Huns."+name +"I mean. It's a luxurious name.");
Random random = new Random();
int newNameIndex = random.nextInt(name.length());
String newName = name.substring(newNameIndex,newNameIndex+1);
System.out.println("From now on your name is"+newName+"It is. Mind you,"+newName+"That's right. I'll reply when I understand"+newName+"!!");
}
}
Here is the code. If you copy this to Eclipse or IntelliJ, it will work. Although "Implementing Yubaba" does not mean that Yubaba itself is completely reproduced, only the scene where Yubaba hires Chihiro as an employee, which is one of the famous scenes of "Spirited Away", is reproduced. It will be. ~~ I'm sorry for those who expected ~~
Yubaba first gives you a contract.
import java.util.Scanner;
//~~~~~~
System.out.println("It's a contract. Write your name there.");
Scanner keiyakusho = new Scanner(System.in);
String name = keiyakusho.nextLine();
System.out.println("Huns."+name +"I mean. It's a luxurious name.");
Use the Scanner class to take name input from the console and save it in a variable.
Next, Yubaba robs her name.
import java.util.Random;
//~~~~~~
Random random = new Random();
int newNameIndex = random.nextInt(name.length());
String newName = name.substring(newNameIndex,newNameIndex+1);
A random number is generated with 0 or more and less than 0 (the number of input characters), and one character is randomly selected from the input character string and extracted.
System.out.println("From now on your name is"+newName+"It is. Mind you,"+newName+"That's right. I'll reply when I understand"+newName+"!!");
Then give the extracted character as a new name.
Someone who is savvy or savvy in Java may have noticed it when they saw the full code. "Hey, this guy" ** If the name input is blank ** "I haven't written the process." That's right. This code ** doesn't dare to write what to do if the name is blank **. So if you leave the name input blank, it's a little programmer-like material code that ** Yubaba crashes **. ~~ A power word called Crash Yubaba ~~ Yubaba seems to be interesting, like a crash. Also, even in the movie, there was no line when the name input was blank, so please forgive me because it is more faithful to the movie if I do not do so (desperate excuse). ~~ I didn't crash ~~
Thank you for reading this far. I tried to implement Yubaba in Java, so I implemented Ja Auntie. All the content is over with the story, but I hope you can read it. ~~ If you are killed by Ghibli fan or Tetsuko Kuroyanagi, please pick up only the bones ~~
Recommended Posts