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:

1 Enter text: A: 1 2B: 2 3 C: 3 4D: 4 5E: 5 l Enter text 2A: 1 3 B: 2 4C: 3 5D: 4 6 E: 5

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

.....

.....

*/

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: 1 Enter te
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: 1 Enter te

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site