String operation Try to make Java problem TypeScript 9-3

Select the execution result of the following program

java.java


public class Main{
 public static void main(String[] args){
  String str = "abcde";
  System.out.println(str.charAt(5));
 }
}

A.d is displayed B.e is displayed C. Nothing is displayed D.null is displayed E. A compile error occurs F. Exception is thrown at runtime

The answer is F.

str.charAt (5) takes an integer as an argument and returns the character at that location with the argument as an index. Since the string str has only 5 characters, the index is numbered 0 to 4 and is thrown (runtime error) because there is no 5th. The answer is F because there is no grammatical problem and it is thrown without compilation errors.

If you do this with TypeScript

TypeScript.ts


   var str:string = "abcde";
   console.log(str.charAt(5));

Write like this.

TypeScript compiles fine because the throw is a run-time error. Also, js does not give an error in this case, so a blank is displayed.

Recommended Posts

String operation Try to make Java problem TypeScript 9-3
Interface Try to make Java problem TypeScript 7-3
Increment behavior Try to make Java problem TypeScript 3-4
Initialization of for Try to make Java problem TypeScript 5-4
[Java] Try to solve the Fizz Buzz problem
Try to solve a restricted FizzBuzz problem in Java
Java --How to make JTable
Declaration of multidimensional array Let's try TypeScript for Java problem 4-4
[Beginner] Try to make a simple RPG game with Java ①
Operation to connect multiple Streams @Java
Try to make a simple callback
How to make a Java container
[Java] Try to implement using generics
Try to extract java public method
Try to implement Yubaba in Java
CompletableFuture Getting Started 2 (Try to make CompletableFuture)
Try to make a peepable iterator
How to make a Java array
[Java] Try to solve the Fizz Buzz problem using recursive processing
How to make a Java calendar Summary
Try to solve Project Euler in Java
Easy to make Slack Bot in Java
Java string
[Java] Convert Object type null to String type
How to make a Discord bot (Java)
How to output Java string to console screen
[Java] Beginners want to make dating. 1st
Let's migrate to make Java more comfortable
Type conversion from java BigDecimal type to String type
Try to build Java8 environment on Amazon Linux2
I tried to make Basic authentication with Java
Code to escape a JSON string in Java
I did Java to make (a == 1 && a == 2 && a == 3) always true
Try to create a bulletin board in Java
Try to link Ruby and Java with Dapr
Try to make a music player using Basic Player
Try to implement TCP / IP + NIO with JAVA
How to solve an Expression Problem in Java
Easy to make LINE BOT with Java Servlet
How to write Java String # getBytes in Kotlin?
[Java] How to make multiple for loops single
[Java] String padding
Try Java 8 Stream
[Java] Problem No. 2
[Java] Problem No.3
Java string processing
[Java] Introduction to Java
[Java] Problem No.1
Introduction to java
Split string (Java)
Roughly try Java 9
<java> Read Zip file and convert directly to string
Sample code to convert List to List <String> in Java Stream
How to make Java unit tests (JUnit & Mockito & PowerMock)
Try to make an addition program in several languages
I tried to make a login function in Java
[Java] How to cut out a character string character by character
[Java] How to erase a specific character from a character string
Try connecting to AzureCosmosDB Emulator for Docker with Java
Try to build a Java development environment using Docker
I used to make nc (netcat) with JAVA normally