[英]Splitting the input number in Java
嗨,我的代碼有問題,我想要輸入數字。 與其在一個對話框中顯示數字,不如在每個對話框中顯示數字,而是查看代碼。
import javax.swing.JOptionPane;
public class Vector_number {
public static void main(String[] args) {
String x;
int i = 0;
int number;
int[] y;
y = new int[10];
x = JOptionPane.showInputDialog("Enter integer: ");
number = Integer.parseInt(x);
String myStr = " ";
while (number > 0) {
y[i] = number%10;
number = number/10;
i++;
}
for (i = i-1; i >= 0 ; i--) {
JOptionPane.showMessageDialog(null, y[i]+ " ",
"Weeeee", JOptionPane.PLAIN_MESSAGE);
System.exit(0);
}
}
}
當然。 您在for循環中調用對話框。
另外,根本不要使用System.exit。
首先構建字符串,然后顯示對話框
StringBuilder str = new StringBuilder();
for (i = i-1; i >= 0 ; i--) {
str .append( y[i]).append(" ");
}
JOptionPane.showMessageDialog(null, str.toString, "Weeeee", JOptionPane.PLAIN_MESSAGE);
不要顯示“ i”選項窗格,而是先從數組中收集所有數字,然后在一個窗格中顯示它們。 嘗試
`for(i=i-1;i>=0;i--){
myStr+=" "+y[i];
}
JOptionPane.showMessageDialog(null, myStr,...`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.