Spacing Issue in JAVA ECLIPSE So Im having the following pro

Spacing Issue in JAVA ECLIPSE

So I\'m having the following problem when running my programming (I have an extra line) (See picture below).

Could you try to fix my code in the \'for\' loop in the end. Please do not remove the last line which is \"System.out.println();\" because that needs to be there. Thanks!

import java.util.Scanner;

import java.io.*;

public class ProgrammingAssignment9 {

   public static void main(String args[])

   {

   Scanner input=new Scanner(System.in);

   String input1=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(input.hasNext()){
   temp=input.nextLine();//used to read string

   input1=input1.concat(temp);//putting temp string to main string
   }
  
   c=input1.toCharArray();//converting string to char[]

   for(int i=0;i<c.length;i++){
         
         
       if(Character.isDigit(c[i])) {
       System.out.println();
       System.exit(0);
       }  
         
   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 an array
       }
   }
  
   }
     
     
   for(int i=0;i<a.length;i++)

   {
         
       if(a[i] > 0){

   System.out.printf((\"%c: \") + (\"%d\"), i + 65 , a[i]);
   System.out.println();
       }
   }
System.out.println();
   }
   }

Solution

import java.util.Scanner;
import java.io.*;
public class ProgrammingAssignment9 {
public static void main(String args[])
{
Scanner input=new Scanner(System.in);
String input1=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;
int temp1 = 0;

System.out.print(\"Enter text: \");

{
while(input.hasNext()){
temp=input.nextLine();//used to read string
if(temp.equals(\"exit\")){
   break;
}
input1=input1.concat(temp);//putting temp string to main string
}
  
c=input1.toCharArray();//converting string to char[]
for(int i=0;i<c.length;i++){


if(Character.isDigit(c[i])) {
System.out.println();
System.exit(0);
}

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 an array
// keeping the index till when we have the characters
if(index>temp1)
   temp1=index;
}
}
  
}


for(int i=0;i<a.length;i++)
{

if(a[i] > 0){
System.out.printf((\"%c: \") + (\"%d\"), i + 65 , a[i]);
//giving the new line till when temp1= not equal to ith index
if(i!=temp1)
   System.out.println();
}
}
System.out.println();
}
}

Please feel free to ask doubts. God bless you

Spacing Issue in JAVA ECLIPSE So I\'m having the following problem when running my programming (I have an extra line) (See picture below). Could you try to fix
Spacing Issue in JAVA ECLIPSE So I\'m having the following problem when running my programming (I have an extra line) (See picture below). Could you try to fix
Spacing Issue in JAVA ECLIPSE So I\'m having the following problem when running my programming (I have an extra line) (See picture below). Could you try to fix

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site