Saturday 6 February 2010

Programme that input ten numbers from the user and print number of occurrence of those numbers.

import java.util.Scanner;

public class occurrence{

public static void main(String [] args){

int a=0, b, take, count=1, hum, dev, sta, count2=0;

int x[]= new int[10];

Scanner input = new Scanner(System.in);

while(a<10){

x[a]=input.nextInt();

a++;

}

b=0;

int why=0, m=0;

while(why<9){

m = why;

b=why;

count=1;

while(b<9){

hum=x[m];

sta=b+1;

dev=x[sta];

if(hum==dev){

count = count + 1;

}

b++;

}

int mgt=0;

if(count>=1){

count2=0;

while(mgt<m){

int hhh, rock;

hhh=x[m];

rock=x[mgt];

if(hhh==rock){

count2=1;

}

mgt++;

}

if(count2==1){}

else{

System.out.println(x[m]+ ":" + count + " times ");

}

}

why++;

}

int eco=0;

count2=0;

while(eco<9){

int hhh, rock;

hhh=x[9];

rock=x[eco];

if(hhh==rock){

count2=1;

}

eco++;

}

if(count2==1){}

else{

System.out.println(x[9]+ ":" + 1 + " times ");

}

}

}

No comments:

Post a Comment