阿盧今天為了趕作業連熱舞都沒去~
練完管樂回來的時候
就開始幫他寫
除了讓使用者輸入的部份,剩餘的都是我寫的
底下這部分是阿盧所寫
----------------------------------------------------------------------
import java.util.Scanner;

public class prog1
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int[] g = new int[50];
int index;
System.out.println("請輸入一串數列,最多50個");
System.out.println("當輸入0時結束");
for (index = 0; index < 50; index++)
{
g[index] = keyboard.nextInt();
if (g[index] == 0)
break;
}
-------------------------------------------------------------------------------
這題是要讓使用者輸入數字
50個以下,可以重複
印出來的結果是排序及個數
EX:1,2,3,5,1,9,10,-12,2,5,5,3
Print:
N Count
10 1
9 1
5 3
3 2
2 2
1 2
-12 1

以下為程式碼
______________________________________________________________________________________________________
import java.util.Scanner;

public class prog1
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int[] g = new int[50];
int index;
System.out.println("請輸入一串數列,最多50個");
System.out.println("當輸入0時結束");
for (index = 0; index < 50; index++)
{
g[index] = keyboard.nextInt();
if (g[index] == 0)
break;
}
int temp;
for(int i=0;i {
for(int j=0;j {
if(g[j] {
temp=g[j];
g[j]=g[j+1];
g[j+1]=temp;
}
}
}
System.out.println("N" + "\t" + "Count");
int[] x = new int[g.length];
for (int j = 0; j < g.length; j++)
{
int count = 0;
for(int i = 0; i < g.length; i++)
{
if (g[j] == g[i])
count++;
}
if (j!=0)
{
if (g[j] == g[j-1])
continue;
}
x[j]=count;
if (g[j] != 0)
{

System.out.print(g[j]+"\t");
System.out.println(x[j]);
}
}

}

}
__________________________________________________________________________________________________________
arrow
arrow
    全站熱搜

    nnosnhoj 發表在 痞客邦 留言(0) 人氣()