Professional Documents
Culture Documents
leaf. The data points are input by the user from keyboard. This program will display the
output similar to the one shown below:
If you are not sure about how to present data set in the form of stem and leaf, you will
need to read this page:
Solution:
import java.util.Scanner;
int n;
//
//find mode
mode[0][0]=1;
int count=1;
for(int i=count-1;i<n;i++){
for(int j=count-1;j<n-1;j++){
if(stem_leaf[i][0]==stem_leaf[j+1][0]) {count++;mode[i][0]++;mode[i][1]=stem_leaf[i][0];}
else if(i==0) mode[i][1]=stem_leaf[i][0];}
}
System.out.println();
System.out.println("Stem and Leaf Display:");
System.out.println("Frequency\tStem\tLeaf");
System.out.println("================================");
int c=0,leaf=0;
for(int i=0;i<n;i++){
if(mode[i][1]!=0){
leaf+=mode[i][0];
System.out.format("%-18d",mode[i][0]);
System.out.format("%-6d",mode[i][1]);
for(int j=c;j<leaf;j++){
System.out.format("%s",stem_leaf[j][1]);}
c=leaf;
System.out.println();
}
}