我有一个带有一些随机数的外部文件,但有些是重复的。我需要编写一个程序来读取数字并打印出所有数字。然后我需要编写一个程序然后打印所有数字而不重复这是我到目前为止所拥有的。如果我的格式在这个问题上不正确,我道歉。我是Stack的新手。
<relativelayout android:ID="brownlayout"..>
<relativelayout android:ID="green layout"./>
<relativelayout/>
答案 0 :(得分:0)
您可以使用集合修改代码。 这会更简单。
public static void main (String [] args)throws Exception
{
Scanner sf = new Scanner(new FileInputStream("prog415h.dat"));
int[] number = new int[100];
int count = 0;
Runner runner = new Runner();
while(sf.hasNextLine())
{
number[count] = sf.nextInt();
System.out.println("The orginal set of numbers are: " + number[count] + " ");
count++;
}
runner.setNumbers(number);
runner.Repeat();
}
}
class Runner
{
public static int[] numbers;
public static void setNumbers(int[] numbers)
{
Runner.numbers = numbers;
}
public static void Repeat()
{
Set<Integer> uniqueElements = new HashSet<Integer>();
System.out.println("List of Unique elements");
for (int i = 0; i < numbers.length; i++)
{
if(!uniqueElements.contains(numbers[i]))
{
uniqueElements.add(numbers[i]);
System.out.println(numbers[i]);
}
}
System.out.println();
}
}
答案 1 :(得分:0)
LinkedHashSet应该做的伎俩
ALTER PROC [ex1].[xml_sp2]
@careteamid int
as
declare @x xml
exec @x = ex1.xml_sp1
@careteamid = @careteamid
select @x as XMLData