[英]Input of different data types seperated by a space
我想輸入一個整數,然后輸入一個空格,相同數量的字母(不帶空格)必須分別處理(例如字符數組的元素)。
根據您描述的規格猜測,是這樣的嗎?
import java.util.Scanner;
class DiffDataTypes{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int integerNum = sc.nextInt(); // input a integer number
char charArray[] = new char[integerNum]; // same number of alphabets without space each processed individually(like elements of character array)
charArray = sc.next().toCharArray();
System.out.print(integerNum + " : ");
for (int i = 0; i < integerNum; i++)
System.out.print(charArray[i]);
System.out.println();
}
}
輸入:
3 happy
輸出:
3 : hap
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.