Question

the following is in java
find the errors and answer the question
what would the output be if the program was functioning and the following was entered
Obect-Orientated Programming Systems Languages Applications

import java. Scanner: public class LabProgram { public static String create acconym String usssPhrase) { string total Acronym

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The answer to this question is as follows:

The modified code is as follows:

import java.util.*;
public class MyClass {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
String inputPhrase;
String userAcronym;
inputPhrase=sc.nextLine();
userAcronym=createAcronym(inputPhrase);
System.out.println(userAcronym);
}
public static String createAcronym(String userPhrase)
{
String totalAcronym;
int i;
totalAcronym="";
for(i=0;i<userPhrase.length();i++)
{
if(i!=userPhrase.length()-1)
{
  
if(i==0)
{

if(userPhrase.charAt(i)>=65 & userPhrase.charAt(i)<=90)
{
totalAcronym+=userPhrase.charAt(i);
}
}
else if(Character.isWhitespace(userPhrase.charAt(i)))
{
if(userPhrase.charAt(i+1)>=65 && userPhrase.charAt(i+1)<=90)
totalAcronym+=userPhrase.charAt(i+1);
  
}
}
}
return totalAcronym;
}
}

The list of errors is as follows:

1.Line 27: cannot convert the Int to String

2. Line 28 cannot find the variable userAcroynm

Line 8:

cannt find the variable named i

Line 9: The if condition is (i==0)

Line Declare the variable i instead of the j1 and replace in the for loop

Line 4: There is no type string in java in the string the s should be capital

Line 7: In for loop the valeu for the assignment should be = but not ==

Line 16: remove the value at the end of the if condition

Line 29: System.out.prinltn should be there instead of the system.print

Line 24: The scanner statement should be Scanner scnr=new Scanner(System.in);

Add a comment
Know the answer?
Add Answer to:
the following is in java find the errors and answer the question what would the output...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please help me fix my errors. I would like to read and write the text file...

    Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList {    Node head;    class Node    {        int data;        Node next;       Node(int d)        {            data = d;            next = null;        }    }    void printMiddle()    {        Node slow_ptr...

  • The following code is a Java code for insertion sort. I would like this code to...

    The following code is a Java code for insertion sort. I would like this code to be modified by not allowing more than 10 numbers of integer elements (if the user enters 11 or a higher number, an error should appear) and also finding the range of the elements after sorting. /* * Java Program to Implement Insertion Sort */ import java.util.Scanner; /* Class InsertionSort */ public class InsertionSortTwo { /* Insertion Sort function */ public static void sort( int...

  • java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then...

    java create java program that make stack with LinkedList and stack is implement iterator. When stack’s iterator call next(), it pop its data. here is the example of output //by user 5 1 2 3 4 5 //then output comes like this 5 4 3 2 1 Stack is empty. here is the code that i'm going to use class Stack<T> implements Iterator<T> {    LinkedList<T> list;       public Stack() {        list = new LinkedList<T>();    }       public boolean isEmpty() {        return list.isEmpty();   ...

  • Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains...

    Finish FormatJavaProgram.java that prompts the user for a file name and assumes that the file contains a Java program. Your program should read the file (e.g., InputFile.java) and output its contents properly indented to ProgramName_Formatted.java (e.g., InputFile_Formatted.java). (Note: It will be up to the user to change the name appropriately for compilation later.) When you see a left-brace character ({) in the file, increase your indentation level by NUM_SPACES spaces. When you see a right-brace character (}), decrease your indentation...

  • design two java classes The example of output would be this: user puts the amount of...

    design two java classes The example of output would be this: user puts the amount of money: (for example 9000) I'm going to get three things 1. Cellphone cost: 3000 2. Laptop cost: 6000 3. Macbook cost: 4000 From now on, my balance would be (+balance) and I bought cellphone, laptop, (since there is not enough amount of money, I can only buy cellphone and laptop. if there is enough money then it can buy all things) so I have...

  • Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print...

    Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print just the last lines of each paragraph in HTML format. Copy and paste the Sample input on the console then print the Expected output. import java.util.Scanner; public class Exercise1 { /** A simple static string for HTML & table header. */ private static final String HTMLHeader = "<!DOCTYPE html>\n" + " <html>\n" + " <head>\n" + " <title>CSE: Exercise 1</title>\n" + " </head>\n" +...

  • JAVA getting the following errors: Project4.java:93: error: ']' expected arr[index] = newVal; // LEAVE THIS HERE....

    JAVA getting the following errors: Project4.java:93: error: ']' expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:93: error: ';' expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:93: error: <identifier> expected arr[index] = newVal; // LEAVE THIS HERE. DO NOT REMOVE ^ Project4.java:94: error: illegal start of type return true; ^ Project4.java:98: error: class, interface, or enum expected static int bSearch(int[] a, int count, int key) ^ Project4.java:101: error: class, interface, or...

  • Thanks for any help you can offer!! Question 11 what are the outputs from print statement...

    Thanks for any help you can offer!! Question 11 what are the outputs from print statement respectively. If you give the user inputs below for the following program? inputs un inputChar: inputString Wish you have a very happy holiday input 2: InputChare InputString Wish you a merry Christmas import java.util.Scanner: public class LabProgram! public static void main(String args) Scanner input = new Scanner(System.in); char InputChar: String inputString int numChars = 0; int i0 inputChar input.next().charAt(o InputString input.nextLine(): while (<inputString_length()) {...

  • JAVA

    Write a Java class (program) which inputs a simple integer and outputs a list of values from the input variable down to 0 (not including 0). You should only show every other value in the output, starting with the input value. You must use a for loop.For example, if the input is 23, the output should be:The input value was 2323 21191715131197531Code given:import java.util.Scanner;/**  * This program counts down from the input number down to (but not including)   * 0, skipping...

  • Write a java programm that calculates the total of a retail sale should ask the user...

    Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors. import java.util.Scanner; public class SalesTax...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT