输入逗号(特定符号间隔的数字)
以字符串的形式输入,通过split(‘punctuation’)分割,通过字符串数组保存分割到的 == 数字字符串==,利用Integer.parseInt()并将结果存入数组中。
Scanner scan = new Scanner (System.in);
String in = scan.nextLine();
String numS[]=in.split(",");
int[] num = new int [numS.length];
for(int i = 0 ; i < numS.length;i++)
{
num[i]=Integer.parseInt(numS[i]);
}
for(int i=0;i<numS.length;i++)
{
System.out.println(num[i]);
}
System.out.print(num); ///hahah
literals (字面上,文本)
You may have noticed that the new keyword isn’t used when initializing a variable of a primitive type. Primitive types are special data types built into the language; they are not objects created from a class. A literal is the source code representation of a fixed value; literals are represented directly in your code without requiring computation. As shown below, it’s possible to assign a literal to a variable of a primitive type:
boolean result = true;
char capitalC = 'C';
byte b = 100;
short s = 10000;
int i = 100000;
long 型数据需要在后面加上l或L 默认使int
float 后面加上F或f 默认使double
long
long类型的整数常数结尾一定为l或L(不区分大小写)。
♂DOM解析XML文件♂
转载:https://blog.csdn.net/a1353206432/article/details/80583302
public class Exercise{
public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException {
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builder=factory.newDocumentBuilder();
Document doc = builder.parse("src\\HelloXML.xml");
NodeList node = doc.getElementsByTagName("linkman");
for(int i=0;i<node.getLength();i++)
{
Element e = (Element)node.item(i);
System.out.println("name "+e.getElementsByTagName("name").item(0).getFirstChild().getNodeValue());
System.out.println("email "+e.getElementsByTagName("mail").item(0).getFirstChild().getNodeValue());
}
}
}
JDBC JDK8 MySQL8.0.18 Connection/J 8.0.18
使用Connection/J中的驱动的时候需要修改Class.forName()中的参数为“com.mysql.cj.jdbc.Driver”
这里一定要注意Driver中的D需要大写!
url需要显示端指定关闭ssl即useSSL=false;
同时需要配置时区即&serverTimezone=地点
转载:https://blog.csdn.net/kikock/article/details/80413475
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import com.mysql.cj.xdevapi.Statement;
public class BataBase {
public static void main(String[] args) throws ClassNotFoundException, SQLException {
// TODO Auto-generated method stub
//System.out.println("ShuZhiYuan");
/*
* JDBC 四大配置参数
* >driverClassName: com.mysql.jdbc.Driver
* >url:jdbc:mysql://localhost:3306/数据库名
* >username:root
* >password:123456
*/
String url="jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=Hongkong&characterEncoding=utf-8&autoReconnect=true";
// ? 起连接作用,通过?来带参数,连接域名何参数
//& 不同参数的间隔符
String username="root";
String password="123456";
try {
Class.forName("com.mysql.cj.jdbc.Driver");
}catch(Exception e) {
System.out.println("加载驱动类失败");
}
//DriverManager class manage the establishment of connections
//use Class.forName() to implements the java.sql.Driver interface .If with connector/J ,use the com.mysql.cj.jdbc.Driver.
//obtain a Connection instance to connect particular database By DriverManager.getConnection()
//To create a Statement instance ,use the createStatement()method on the Connection Object.
//using JDBC Statement Object to Execute SQL
//retrieve the results through the ResultSet Class
Connection con = DriverManager.getConnection(url,username,password);
ResultSet rs ;
java.sql.Statement sql;
sql=con.createStatement();
rs=sql.executeQuery("Select * from first_table");
while(rs.