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

Hello I am working on a Java program for anagrams. I need help with getting the

ID: 3758069 • Letter: H

Question

Hello I am working on a Java program for anagrams.

I need help with getting the program to have a newline statement at the end so the user can enter a new anagram!

Please help! thanks!

Program so far:

package anagram;

public class Anagram {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the first word : ");
String st = in.nextLine();
System.out.println("Enter the second word : ");
String st2=in.nextLine();
int a = st.length();
int b = st2.length();
int sum1=0;
int sum2=0;
for(int i = 0;i<a;i++)
{
sum1=sum1+st.charAt(i);
}
for(int i = 0;i<b;i++)
{
sum2=sum2+st2.charAt(i);
}
if(sum1==sum2)
System.out.print(st2+" is an anagram of "+st);
else
System.out.print(st2+" is not a anagram of "+st);
}
String newline;
}

Explanation / Answer

package anagram;

public class Anagram {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the first word : ");
String st = in.nextLine();
System.out.println("Enter the second word : ");
String st2=in.nextLine();
int a = st.length();
int b = st2.length();
int sum1=0;
int sum2=0;
for(int i = 0;i<a;i++)
{
sum1=sum1+st.charAt(i);
}
for(int i = 0;i<b;i++)
{
sum2=sum2+st2.charAt(i);
}
if(sum1==sum2)
System.out.print(st2+" is an anagram of "+st);
else
System.out.print(st2+" is not a anagram of "+st);
System.out.println();
System.out.print
ln();
//Above to two statements will add the required new line.
}
String newline;
}

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