Java ECLIPSE simple question Im trying to get my output to l
Java ECLIPSE simple question.
I\'m trying to get my output to look like how it looks in the left but it looks like the one in the right with my code:
Solution
Hi, Please let me know in case of any issue.
import java.util.Scanner;
public class Test {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String input=new String(\"\");//input string
String temp;//to read strings line by line
char[] c=new char[26];//to store string in characters format
int[] a=new int[26];//to count Number of Characters
char ch,temp1;
System.out.print(\"Enter text: \");
while(sc.hasNext()){
temp=sc.nextLine();//used to read string
input=input.concat(temp);//appending temp string to main string(input
}
c=input.toCharArray();//converting string to char[]
for(int i=0;i<c.length;i++)
{
if(Character.isLetter(c[i]))//to check letter is Character or not
{
if(Character.isLowerCase(c[i]))
c[i]=Character.toUpperCase(c[i]);
int index=c[i]-\'A\';//finding index
int b=a[index];
b++;
a[index]=b;//incrementing value in a array
}//end of if
}//end of for loop
for(int i=0;i<a.length;i++)
{
if(a[i]>0)//if count is greater than 1
System.out.printf(\"%c: %d \ \",i+65,a[i]);
}//end of for llop
}//end of main
}
/*
Sample output:
Enter text: A: 1
B: 2
C: 3
D: 4
.....
.....
*/

