What will happen after the contact of p and n type semiconductors?
时间: 2024-06-03 16:11:21 浏览: 100
After the contact of p and n type semiconductors, electrons from the n-type side will diffuse to the p-type side, and holes from the p-type side will diffuse to the n-type side. This creates a region near the interface called the depletion region, which has no free mobile charge carriers. The resulting electric field causes some of the electrons and holes to recombine, creating a potential difference across the interface known as the built-in potential.
相关问题
What will happen if you try to compile and run the following code? public class Test { public static void main(String argv[]){ Integer anar[]=new Integer[5]; new Integer(5); System.out.println(anar[0]); } }
以下是对你的问题的回答:
这段代码将会在编译和运行时都不会出现任何错误,但是在运行时会产生一个空指针异常。
在这段代码中,创建了一个名为“anar”的Integer对象数组,其长度为5。然而,该数组没有被初始化,因此它的所有元素都被初始化为null。
接下来,创建了一个值为5的新Integer对象,但它没有被分配给数组的任何元素。
最后,当代码尝试打印“anar”数组的第一个元素的值时,它将抛出一个空指针异常,因为第一个元素是null,无法打印其值。
When the user of the software specifies action 4, your program must ask the user to type the name of a user, and a number of books, and the program then uses that number to increase the number of books lent or borrowed by the user. Then the program goes back to the main menu.If the name of the user is wrong, then an UnknownUserException exception will be thrown by the Library object. The code of the main method of your CLI class must catch this exception, print the error message from the exception object, and then it just goes back to printing the menu of actions (by just going back to the beginning of the while loop). Note that, even if a consumer is a borrower, the readPosInt method prevents the typed number of books from being negative. This means a borrower will never throw a NotALenderException. Nevertheless the code of the main method of your CLI class must handle this exception by printing the error message "BUG! This must never happen!" and immediately terminating the program using System.exit(1).
Here's an example implementation of the main method of the CLI class that follows the above requirements:
```java
import java.util.Scanner;
public class CLI {
private static final Scanner scanner = new Scanner(System.in);
private static final Library library = new Library();
public static void main(String[] args) {
while (true) {
printMenu();
int action = readPosInt("Type an action number:");
try {
switch (action) {
case 1:
System.out.println(library.listBooks());
break;
case 2:
String author = readString("Type an author name:");
System.out.println(library.listBooksByAuthor(author));
break;
case 3:
String title = readString("Type a book title:");
System.out.println(library.findBook(title));
break;
case 4:
String user = readString("Type a user name:");
int numBooks = readPosInt("Type a number of books:");
library.lendOrBorrow(user, numBooks);
break;
case 5:
System.exit(0);
default:
System.out.println("Unknown action number.");
break;
}
} catch (UnknownUserException e) {
System.out.println(e.getMessage());
} catch (NotALenderException e) {
System.out.println("BUG! This must never happen!");
System.exit(1);
}
}
}
private static void printMenu() {
System.out.println("Menu:");
System.out.println("[1] List all books");
System.out.println("[2] List books by author");
System.out.println("[3] Find a book by title");
System.out.println("[4] Lend/borrow books for a user");
System.out.println("[5] Quit");
}
private static String readString(String prompt) {
System.out.println(prompt);
return scanner.nextLine().trim();
}
private static int readPosInt(String prompt) {
int num = -1;
while (num <= 0) {
System.out.println(prompt);
try {
num = Integer.parseInt(scanner.nextLine().trim());
} catch (NumberFormatException e) {
System.out.println("Invalid number.");
}
}
return num;
}
}
```
Note that the code uses a `Library` object to perform the actions requested by the user, and catches the `UnknownUserException` and `NotALenderException` exceptions as required.
阅读全文