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

Can anyone tell me why this code is not running in NetBeans? package threeletter

ID: 3875558 • Letter: C

Question

Can anyone tell me why this code is not running in NetBeans?

package threeletteracronym;

import java.util.Scanner;

public class ThreeLetterAcronym {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

Scanner inputDevice = new Scanner(System.in);

String threeWords = null;

String Acronym = null;

boolean Repeat = true;

  

int Count = 1;

int index = 0;

int y;

int x = 0;

System.out.println("Please Enter There words and I'll display their Acronym. >>");

Acronym += Character.toUpperCase(threeWords.charAt(0));

while(index < threeWords.length()-1 && Repeat)

{

if(threeWords.charAt(index) == ' ')

{

Acronym += Character.toUpperCase(threeWords.charAt(index + 1));

Count++;

}

++x;

}

  

  

if (Count != 3)

{

Repeat = false;

index++;

}

System.out.println("Your Acronym is." + Acronym);

}

  

}

Explanation / Answer

import javax.swing.*;

public class ThreeLetterAcronym{

  
public static void main(String[] args){

String phrase = "";
String firstWord = "";
String secondWord = "";
String thirdWord = "";

int x = 0;
int y = 0;

//Get input

phrase = JOptionPane.showInputDialog(null, "Please enter three words");

  
while(x < phrase.length())

{
if(phrase.charAt(x) = '' && phrase.charAt(y));
{
  
firstWord = phrase.substring(0, x);
secondWord = phrase.substring(x +1, y);
thirdWord = phrase.substring(y +1, phrase.length());

y = phrase.length();
}

++x;
++y;

}

JOptionPane.showMessageDialog(null, "Your acronym is" + firstWord.charAt(0)
+ secondWord.charAt(0) + thirdWord.charAt(0));

}

}

The error is occured

if(phrase.charAt(x) = '' && phrase.charAt(y));

it shows error in above line

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