问题描述
要求用户“输入数字:”4 次。 如果输入的不是数字,请再次询问。 输出“成功”。在他们输入了 4 个数字之后。 请使用 while、if、if else 和 do 语句为我回答此代码。
int counter; System.out.print("Input a number: ");
while(!(scan.hasNextInt()));{
for (int i = 0; i < 3; i++){
scan.next();
System.out.print("Input a number: ");
if (!(pass.equals(pass2))) {
counter++;
} else if (!(scan.hasNextInt())) {
}
}
if (counter >= 2) {
System.out.println("Input a number: ");
}
} else if (!(scan.hasNextInt())) { System.out.println("success."); }
这是非常基本的东西,但我很挣扎。
解决方法
Function XML2Arr(strPath As String,strXPath As String)
Dim i As Long,j As Long,ii As Long,jj As Long,jjNew As Long,iHeader As Long
Dim fileName As String,arr
Dim XDoc As Object,nodesList As Object,node As Object
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' writes XML to DOM object
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If Dir(strPath) = "" Then
MsgBox "Appears there is no xml stored at " & vbCrLf _
& strPath & " Exiting..."
End
ElseIf InStrRev(strPath,"*.") > 0 Then 'new full strPath (no wild cards)
strPath = Left(strPath,InStrRev(strPath,"\")) & Dir(strPath)
End If
With CreateObject("Scripting.FileSystemObject")
fileName = .getFileName(strPath)
End With
Application.StatusBar = "Getting XML from " & Chr(34) & fileName & Chr(34) & " ..."
Set XDoc = CreateObject("MSXML2.DOMDocument")
'XDoc.async = False 'Appears not to work on read-only XML
XDoc.validateOnParse = False
XDoc.Load (strPath)
XDoc.SetProperty "SelectionLanguage","XPath"
'XDoc.SetProperty "SelectionNamespaces",XmlNamespaces
Set nodesList = XDoc.SelectNodes(strXPath)
If nodesList.Length = 0 Then
MsgBox ("Appears empty or different formated " & fileName & ". Exiting...")
Exit Function
End If
' 1. get array sizes
ii = nodesList.Length
jj = nodesList(0).ChildNodes.Length 'initial # columns
For i = 1 To ii
jjNew = nodesList(i - 1).ChildNodes.Length
If jjNew > jj Then 'if first row has blanks,reset # col to max
jj = jjNew
iHeader = i - 1
End If
Next
ReDim arr(1 To ii + 1,1 To jj) 'size array
' 2. populate headers
For j = 0 To jj - 1
arr(1,j + 1) = nodesList(iHeader).ChildNodes(j).BaseName
Next
For i = 1 To ii
For j = 0 To jj - 1
If Not (nodesList(i - 1).ChildNodes(j) Is Nothing) Then
arr(i + 1,j + 1) = nodesList(i - 1).ChildNodes(j).Text
End If
Next
Next
XML2Arr = arr
'Arr2Rng arr,"Sheet2",True
End Function