當前位置:首頁 » 編程語言 » 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();
}

}

熱點內容
java返回this 發布:2025-10-20 08:28:16 瀏覽:585
製作腳本網站 發布:2025-10-20 08:17:34 瀏覽:881
python中的init方法 發布:2025-10-20 08:17:33 瀏覽:574
圖案密碼什麼意思 發布:2025-10-20 08:16:56 瀏覽:761
怎麼清理微信視頻緩存 發布:2025-10-20 08:12:37 瀏覽:677
c語言編譯器怎麼看執行過程 發布:2025-10-20 08:00:32 瀏覽:1005
郵箱如何填寫發信伺服器 發布:2025-10-20 07:45:27 瀏覽:249
shell腳本入門案例 發布:2025-10-20 07:44:45 瀏覽:108
怎麼上傳照片瀏覽上傳 發布:2025-10-20 07:44:03 瀏覽:799
python股票數據獲取 發布:2025-10-20 07:39:44 瀏覽:705