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
Write a c program using loops to generate following output.
Keith_Richards [23]

Answer:

#include <stdio.h>

int main()

{

for (int n = 12; n > 0; n--) {

 printf("%d x 2 = %d\n", n, n * 2);

}

}

Explanation:

Only one loop.

8 0
2 years ago
From an IT perspective, which of the following best describes BI and BI apps?
Natali5045456 [20]

Answer:a)Stand-alone

Explanation: Stand-alone application is the application that is found on the system of every client.In accordance with the IT section, Business intelligence can be transferred into stand-alone application .This helps in the development of the essence of the system at an independent level.

Other options are incorrect because supporting a certain factor will not make it independent, cannot act as the group of ISs technology or web system for gaining profit.Thus,the correct option is option(a).

4 0
2 years ago
Given the following adjacency matrix, what is the approximate rank vector after one iteration of the power iteration method (use
ValentinkaMS [17]

Note: The matrix referred to in the question is: M = \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]

Answer:

a) [5/18, 5/18, 4/9]'

Explanation:

The adjacency matrix is  M = \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]

To start the power iteration, let us start with an initial non zero approximation,

X_o = \left[\begin{array}{ccc}1\\1\\1\end{array}\right]

To get the rank vector for the first Iteration:

X_1 = MX_0

X_1 =  \left[\begin{array}{ccc}1/2&1/3&0\\1/2&1/3&0\\0&1/3&1\end{array}\right]\left[\begin{array}{ccc}1\\1\\1\end{array}\right] \\\\X_1 = \left[\begin{array}{ccc}5/6\\5/6\\4/3\end{array}\right]\\

Multiplying the above matrix by 1/3

X_1 = \left[\begin{array}{ccc}5/18\\5/18\\4/9\end{array}\right]

8 0
3 years ago
Helen has no experience in security. She would like to earn a certification that demonstrates that she has the basic knowledge n
rewona [7]

Answer:

Option C. Security+ is the correct answer.

Explanation:

8 0
2 years ago
Which of the following is not regression test case? A. A representative sample of tests that will exercise all software function
AveGali [126]

Answer:

D. Low-level components are combined into clusters that perform a specific software sub-function

Explanation:

Normally, regression testing are done on a manual basis by simply re-executing a subset of the entire available test cases or it can be done automatically by utilizing playback tools or automated capture. Hence, from the options, a combination of low-level components into clusters that perform a specific sub-function does not align with how regression testing are done either manually or automatically.

6 0
3 years ago
Other questions:
  • What can help you best learn about appearance, habitats and behaviors of birds in your area
    9·1 answer
  • How can supply and demand for different careers affect job stability and income?
    6·1 answer
  • Five computers are connected to a switch in a star topology. what type of network is this?
    12·1 answer
  • Select all the items that determine your preference for a concert ticket. a) band that is playing b) date of the concert c) pric
    7·1 answer
  • A network administrator is configuring the triggering mechanism for the network-based IPS by defining a pattern of web surfing a
    10·2 answers
  • When parallel parking, you should select a space that is __________ as long as your car.
    11·1 answer
  • Describe a way that you can envision using the power of the computer through
    13·1 answer
  • Exercise 3.6.9: 24 vs. "24"5 points
    7·1 answer
  • What is the 3 different storage requirements a computer has to process data​
    12·1 answer
  • JAVA -Develop a program that prompts the user to enter a series of 10 integers and then determines and displays the largest and
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!