我试图从一个数组中随机选择打印它,然后将其从数组中删除,以避免两次打印相同的数字.我是一个java新手,所以想知道是否有人可以指出我哪里出错了.
public static void main(String[] args) {
int[] colm = { 1, 2, 3, 4, 5, 67, 87 };
Random rand = new Random();
for (int i = 0; i < 5; i++)
System.out.println(" " + colm[rand.nextInt(colm.length)]);
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我试图println在与数字相同的行上获取 5 的倍数,但它在 atm 中不起作用,它打印在下一行。该代码使用了一个 for 循环,这让我更难有任何建议。
public static void main(String[] args)
{
for(int i=1 ; i<101; i++)
{
System.out.println(" " +i);
if ( i % 2 != 0 && i % 5 == 0 )
System.out.print("This is an odd number and a multiple of 5 \n " );
}
}//main
Run Code Online (Sandbox Code Playgroud)