java编程从键盘上输入10个整数,并将其放入一维数组a中。将下标相差5的元素分为一组。
2个回答
展开全部
Scanner sc=new Scanner(System.in);
int[] a=new int[10];
for(int i=0;i<10;i++){
System.out.println("请输入一个整数:");
a[i]=sc.nextInt();
}
for(int i=0;i<a.length;i++){
if(i+5<10){
System.out.println(a[i]+"和"+a[i+5]+"是一组");
}
}
不知道怎么分组。直接输出了。
追问
我也是不知道怎么把这两个元素弄到一个数组中
追答
感觉要建很多数组,很麻烦的样子。
展开全部
Private Sub Command1_Click()
Dim tmp As String, tmp1 As String, a() As String
Me.Cls
tmp = Text1.Text
If Not IsNumeric(tmp) Then GoTo OutErr
a = Split(tmp, ",")
If UBound(a) <> 9 Then MsgBox "请输入十个整数!", vbInformation, "提示": Exit Sub
For i = 0 To 4
tmp1 = a(i)
a(i) = a(9 - i)
a(9 - i) = tmp1
Next i
For i = 0 To 9
If Int(Val(a(i))) = Val(a(i)) Then
Me.Print a(i) & ",";
Else
Me.Print a(i) & "(不是整数)";
End If
Next i
Exit Sub
OutErr:
a = Split(tmp, ",")
For i = 0 To UBound(a)
If Not IsNumeric(a(i)) Then Me.Print vbCrLf & a(i) & "不是整数"
Next i
End Sub
Private Sub Text1_Change()
Dim a() As String
a = Split(Text1.Text, ",")
If a(UBound(a)) <> "" Then Label1.Caption = "共输入:" & UBound(a) + 1 & "个数"
End Sub
Dim tmp As String, tmp1 As String, a() As String
Me.Cls
tmp = Text1.Text
If Not IsNumeric(tmp) Then GoTo OutErr
a = Split(tmp, ",")
If UBound(a) <> 9 Then MsgBox "请输入十个整数!", vbInformation, "提示": Exit Sub
For i = 0 To 4
tmp1 = a(i)
a(i) = a(9 - i)
a(9 - i) = tmp1
Next i
For i = 0 To 9
If Int(Val(a(i))) = Val(a(i)) Then
Me.Print a(i) & ",";
Else
Me.Print a(i) & "(不是整数)";
End If
Next i
Exit Sub
OutErr:
a = Split(tmp, ",")
For i = 0 To UBound(a)
If Not IsNumeric(a(i)) Then Me.Print vbCrLf & a(i) & "不是整数"
Next i
End Sub
Private Sub Text1_Change()
Dim a() As String
a = Split(Text1.Text, ",")
If a(UBound(a)) <> "" Then Label1.Caption = "共输入:" & UBound(a) + 1 & "个数"
End Sub
追问
java编程啊
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询