Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I make the numbers that I print right justified? Please provide an expla

ID: 3646481 • Letter: H

Question

How can I make the numbers that I print right justified?
Please provide an explanation.
















import java.util.Scanner;

public class JKansas
{
static Scanner sc = new Scanner(System.in );

public static void main(String[] Theory)
{

JWaffles MyWaffles = new JWaffles();

MyWaffles.ProgramHeading();

System.out.println("Enter a string:" );
String SentenceContents = sc.nextLine( );

int SpaceCount = SentenceContents.length() - SentenceContents.replaceAll(" ", "").length( );
int VowelCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[aeiou]", "").length( );
int ConsonantCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)(?=[a-z])[^aeiou]", "").length( );
int SpecialCharCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[^a-z ]", "").length( );
int WordCount = SentenceContents.trim().split("\s+").length;




System.out.println("There are " + VowelCount + " vowels in this sentance" );
System.out.println("There are " + ConsonantCount + " consonants in this sentance" );
System.out.println("There are " + SpaceCount + " spaces in this sentance" );
System.out.println("There are " + SpecialCharCount + " special characters in this sentance");
System.out.println("There are " + WordCount + " words in this sentance" );






}
}

Explanation / Answer

please rate - thanks

use System.out.printf



import java.util.Scanner;

public class JKansas
{
static Scanner sc = new Scanner(System.in );

public static void main(String[] Theory)
{

JWaffles MyWaffles = new JWaffles();

MyWaffles.ProgramHeading();

System.out.println("Enter a string:" );
String SentenceContents = sc.nextLine( );

int SpaceCount = SentenceContents.length() - SentenceContents.replaceAll(" ", "").length( );
int VowelCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[aeiou]", "").length( );
int ConsonantCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)(?=[a-z])[^aeiou]", "").length( );
int SpecialCharCount = SentenceContents.length() - SentenceContents.replaceAll("(?i)[^a-z ]", "").length( );
int WordCount = SentenceContents.trim().split("\s+").length;




System.out.printf("There are %3d vowels in this sentance",VowelCount );
System.out.printf("There are %3d consonants in this sentance",ConsonantCount );
System.out.printf("There are %3d spaces in this sentance",SpaceCount );
System.out.printf("There are %3d special characters in this sentance",SpecialCharCount);
System.out.printf("There are %3d words in this sentance",WordCount );






}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote