1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nana76 [90]
2 years ago
10

Write code to take a String input from the user, then print the first and last letters of the string on one line. Sample run: En

ter a string: surcharge se Hint - we saw in the lesson how to get the first letter of a string using the substring method. Think how you could use the .length() String method to find the index of the last character, and how you could use this index in the substring method to get the last character.
Computers and Technology
1 answer:
Ainat [17]2 years ago
3 0
<h2>Answer:</h2>

//import the Scanner class to allow for user input

import java.util.Scanner;

//Begin class definition

public class FirstAndLast{

   //Begin the main method

    public static void main(String []args){

       

       

       //****create an object of the Scanner class.

       //Call the object 'input' to receive user's input

       //from the console.

       Scanner input = new Scanner(System.in);

       

       //****create a prompt to tell the user what to do.

       System.out.println("Enter the string");

       

       //****receive the user's input

       //And store it in a String variable called 'str'

       String str =  input.next();

       

       //****get and print the first character.

       //substring(0, 1) - means get all the characters starting

       //from the lower bound (index 0) up to, but not including the upper

       //bound(index 1).

       //That technically means the first character.

       System.out.print(str.substring(0,1));

       

       //****get and print the last character

       //1. str.length() will return the number of character in the string 'str'.

       //This is also the length of the string

       //2. substring(str.length() - 1) - means get all the characters starting

       // from index that is one less than the length of the string to the last

       // index (since an upper bound is not specified).

       // This technically means the last character.

       System.out.print(str.substring(str.length()-1));

       

       

       

    }  // end of main method

   

} //end of class definition

<h2>Explanation:</h2>

The code has been written in Java and it contains comments explaining important parts of the code. Kindly go through the comments.

The source code and a sample output have also been attached to this response.

To run this program, copy the code in the source code inside a Java IDE or editor and save it as FirstAndLast.java

Download java
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> java </span>
4c53f66d970acf88b251b2cf41bcdaf6.png
You might be interested in
Convert one billion byte into one storage unit​
notka56 [123]

Answer:

Explanation:

To convert larger units to smaller units (i.e. take a number of gigabytes and convert it down in to megabytes, kilobytes, or bytes) you simply multiply the original number by 1,024 for each unit size along the way to the final desired unit

7 0
2 years ago
Hurry plz
Elanso [62]

Answer: It allows you to locate materials, be aware of your assignments and plan time to get things done.

Hope it helped.

3 0
3 years ago
Which of the following OSI layers is responsible for the segmentation, multiplexing, flow control and host-to-host communication
Lisa [10]

Answer:

Transport Layer

Explanation:

The transport layer which is responsible for end-to-end communication over a network. Transport Layer breaks the data, allocated by Application layer in smaller units called segments. It is used to number every byte in the segment. It is also responsible for error correction and provides reliability to the user. It allows the host to send and receive error corrected data, messages or packets  over a network and ensures  that data should be received in the same sequence in which it was sent.  It also enables multiplexing and flow control.

7 0
3 years ago
Becky is preparing a document for her environmental studies project. She wants to check her document for spelling and grammar er
Sunny_sXe [5.5K]
If it's MS Word (it probably is), then it's Alt + F7
7 0
2 years ago
Read 2 more answers
Which of the four digital-to-analog conversion techniques (ASK, FSK, PSK or QAM) is the most susceptible to noise? Defend your a
grigory [225]

Answer:

ASK

Explanation:

The correct answer is ASK which denotes Amplitude Shift Keying. This is essentially a type of amplitude modulation which represents the binary data that comes varied forms right in the amplitude of a signal.

Now the reason why It is the most susceptible technique to noise is due to the fact that between frequency, phase & amplitude, amplitude is the one that is most susceptible to being affected by noise when compared to the other two.

3 0
2 years ago
Other questions:
  • Create a Python for loop script of exactly 2 lines of code that generates a sequence of integer numbers that start in zero and g
    12·1 answer
  • ll of the following are extra precautions you can take to secure a wireless network EXCEPT ________. Select one: A. turn on secu
    9·1 answer
  • PLEASE HELP
    15·2 answers
  • The business case for using grid computing involves all of the following except: speed of computation. cost savings. agility. in
    5·1 answer
  • How is a technical certificate like a computer-related associate degree?
    12·2 answers
  • Assuming that we only support BEQ and ADD instructions, discuss how changes in the given latency of this resource affect the cyc
    7·1 answer
  • Define a function called 'findWordFreq, which takes two parameters. The first parameter, 'text" is an nltk.text.Text object and
    8·1 answer
  • Please help! first one to answer correctly gets brainliest and thanked
    7·1 answer
  • What is the answer ????​
    13·2 answers
  • 5 points)*list all of the data that needs to be kept track of for the scenario above in a 1nf (flat file) table (20 points)*use
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!