當前位置:首頁 » 編程語言 » java多行輸入

java多行輸入

發布時間: 2023-01-20 13:01:07

1. 如何用java有選擇的輸入多行文本

1.如果現在所讀取到的字元不是
我們想要的
,那麼就一直向下讀取,直到讀取到我們想要的
2.如果遇到了
返回值
為-1的情況,退出,表示文件讀取完成(這一步一定要放在中間判斷)
3.如果現在讀取的是我們想要的,就一直讀取,直到出現我們不需要的,退出,等待下一次讀取。

2. java里怎麼輸入多行字元 且以指定的字元結束

public static void main(String[] args) {

// TODO Auto-generated method stub

System.out.println("請輸入內容,輸入「end」結束:");

Scanner sc=new Scanner(System.in);//獲取控制台輸入

String str="";

List<String> str_list=new ArrayList<String>();//存儲輸入的字元

while (!str.equals("end")) {

str=sc.nextLine();

str_list.add(str);

}

for(int i=0;i<str_list.size();i++){

System.out.println(str_list.get(i));

}

}

3. 求問,java中如何進行多行輸入

第一行輸入數組的元素個數,第二行輸入數組的元素,代碼如下:

import java.util.Scanner;

public class Test

{

public static void main(String[] args)

{

Scanner in=new Scanner(System.in);

System.out.println("輸入數組元素個數");

int n=in.nextInt();

int[] a=new int[n];

System.out.println("輸入數組元素");

for(int i=0;i<n;i++)

a[i]=in.nextInt();

System.out.println("數組如下:");

for(int i=0;i<n;i++)

System.out.print(a[i]+" ");

}


}

4. java怎麼將選中的多行數據插入表中

java 連接資料庫時,往資料庫一次添加多條數據,可以在 DAO 層,使用
executeBatch0批量插入數據,如下代
碼:
conn = DBToolkit .getConnection0;
Statement stmt =
conn . createStatementO ; j //連續添加多條 SQL
stmt . addBatch (" insert into testdb . book ( kind , name ) values ( java ', java in j
aciton )");
stmt . addBatc (" insert into testdb . book ( kind , name ) values ( c ',』 c in aciton )");//執行批量執行
stmt .executeBatch0);

5. java窗口設計中, 如何設置多行輸入框

用網格布局寫了個簡單的例子!~想美觀可使用GridBagLayout布局方式。

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

public class Login extends JFrame implements ActionListener {

private static final long serialVersionUID = -2890322100614715274L;

//文本框
private JTextField jtf = null;
private JPasswordField jpf = null;
private JLabel jl = null;

public Login() {
// TODO Auto-generated constructor stub
//獲取容器
Container c = this.getContentPane();
//設置布局方式, 網格布局 3行2列
c.setLayout(new GridLayout(3, 2));

jtf = new JTextField();
jpf = new JPasswordField();

JButton b = new JButton("顯示");
// 添加按鈕監聽
b.addActionListener(this);

jl = new JLabel();

c.add(new JLabel("用戶名:"));
c.add(jtf);
c.add(new JLabel("密 碼:"));
c.add(jpf);
c.add(b);
c.add(jl);

this.pack();
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

/**
* 事件監聽方法.
* <p>Title: actionPerformed</p>
* <p>Description: </p>
* @param e
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
//獲取監聽 組件的文本
String str = e.getActionCommand();
if("顯示".equals(str)) {
jl.setText("用戶名是:" + jtf.getText() + "\n密碼是:" + new String(jpf.getPassword()));
}

}

public static void main(String[] args) {
new Login();
}

}

熱點內容
ftp命令批量下載文件 發布:2025-07-18 11:58:45 瀏覽:742
nba2k17文件夾 發布:2025-07-18 11:48:53 瀏覽:869
朔源碼是什麼 發布:2025-07-18 11:44:33 瀏覽:773
迷你世界解壓劇場 發布:2025-07-18 11:43:48 瀏覽:153
linux安裝opencv 發布:2025-07-18 11:42:10 瀏覽:445
編程游戲的軟體有哪些 發布:2025-07-18 11:41:34 瀏覽:956
c程序設計語言電子書 發布:2025-07-18 11:35:58 瀏覽:642
lightning耳機如何在安卓手機上用 發布:2025-07-18 11:21:47 瀏覽:174
妄想山海新宿怎麼配置好 發布:2025-07-18 11:07:43 瀏覽:615
androidsaxxml解析xml 發布:2025-07-18 10:57:58 瀏覽:386