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
Karolina [17]
3 years ago
13

Write a program that prompts the user to enter a string (may contain spaces) and displays its last character. Enter s string: Pr

ogramming is fun The last character is n
Computers and Technology
1 answer:
STALIN [3.7K]3 years ago
3 0

Answer:

<em>The programming language in Python is as follows:-</em>

#Prompt user for input string

userinput = input("Enter a string: ")

#Print the last character of the input

print("The last character is "+userinput[-1])

#End of Program

Explanation:

This line is a comment

#Prompt user for input string

This line prompts user for input

userinput = input("Enter a string: ")

This line is also a comment

#Print the last character of the input

This next line prints the last character of the input string; the last character is defined by the index -1

print("The last character is "+userinput[-1])

You might be interested in
1. Write a telephone lookup program. Read a data set of 1, 000 names and telephone numbers from a file that contains the numbers
Fed [463]

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

Explanation:

PhoneLookup.java

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class PhoneLookup

{

  public static void main(String[] args) throws IOException

  {

     Scanner in = new Scanner(System.in);

     System.out.println("Enter the name of the phonebook file: ");

     String fileName = in.nextLine();

     LookupTable table = new LookupTable();

     FileReader reader = new FileReader(fileName);

     table.read(new Scanner(reader));

   

     boolean more = true;

     while (more)

     {

        System.out.println("Lookup N)ame, P)hone number, Q)uit?");

        String cmd = in.nextLine();

       

        if (cmd.equalsIgnoreCase("Q"))

           more = false;

        else if (cmd.equalsIgnoreCase("N"))

        {

           System.out.println("Enter name:");

           String n = in.nextLine();

           System.out.println("Phone number: " + table.lookup(n));

        }

        else if (cmd.equalsIgnoreCase("P"))

        {

           System.out.println("Enter phone number:");

           String n = in.nextLine();

           System.out.println("Name: " + table.reverseLookup(n));

        }

     }

  }

}

LookupTable.java

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

/**

  A table for lookups and reverse lookups

*/

public class LookupTable

{

  private ArrayList<Item> people;

  /**

     Constructs a LookupTable object.

  */

  public LookupTable()

  {

      people = new ArrayList<Item>();

  }

  /**

     Reads key/value pairs.

     "at"param in the scanner for reading the input

  */

  public void read(Scanner in)

  {

     while(in.hasNext()){

         String name = in.nextLine();

         String number = in.nextLine();

         people.add(new Item(name, number));

     }

  }

  /**

     Looks up an item in the table.

     "at"param k the key to find

     "at"return the value with the given key, or null if no

     such item was found.

  */

  public String lookup(String k)

  {

     String output = null;

     for(Item item: people){

         if(k.equals(item.getName())){

             output = item.getNumber();

         }

     }

     return output;

  }

  /**

     Looks up an item in the table.

     "at"param v the value to find

     "at"return the key with the given value, or null if no

     such item was found.

  */

  public String reverseLookup(String v)

  {

      String output = null;

         for(Item item: people){

             if(v.equals(item.getNumber())){

                 output = item.getName();

             }

         }

         return output;

  }

}

Item.java

public class Item {

  private String name, number;

 

  public Item(String aName, String aNumber){

      name = aName;

      number = aNumber;

  }

 

  public String getName(){

      return name;

  }

 

  public String getNumber(){

      return number;

  }

}

input.txt

Abbott, Amy

408-924-1669

Abeyta, Ric

408-924-2185

Abrams, Arthur

408-924-6120

Abriam-Yago, Kathy

408-924-3159

Accardo, Dan

408-924-2236

Acevedo, Elvira

408-924-5200

Acevedo, Gloria

408-924-6556

Achtenhagen, Stephen

408-924-3522

Kindly check the attached output image below.

3 0
3 years ago
Create a stack with three integers and then use .toarray to copy it to an array.
Marizza181 [45]

Answer:

import java.util.*;

import java.lang.*;

import java.io.*;

class Codechef

{

public static void main (String[] args)

{

    Stack<Integer> mat=new Stack<Integer>();

    mat.add(1);

    mat.add(3);

    mat.add(6);

    System.out.println(mat);

    Object [] a=mat.toArray();

    for(int i=0;i<a.length;i++)

    System.out.println(a[i]);

}

}

Explanation:

An integer type stack st is created;

1,3 and 6 are added to the stack.

printing the contents of the stack.

array a is created form the stack using toArray().

Then printing the array.

6 0
3 years ago
Global knowledge is the same as common knowledge.
slava [35]

Answer:

OT

Explanation:

8 0
3 years ago
Read 2 more answers
Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "non-negative" otherwise. Ex:
Goryan [66]

Answer:

PROGRAMMING APPROACH:

  • Define the necessary header file using namespace.
  • Define the main() method.
  • Declare variable inside the function().
  • Print result.

Explanation:

Required C++ Code:

#include<iostream>

#include<string>

using namespace std;

int main()

{

  string condStr;

  int userVal;

  cin>>userVal;

  condStr=(userVal<0)?("negative"):("non-negative");

  cout<<userVal<< " is "<< condStr <<"."<<endl;

}

OUTPUT:

-2

-2 is negative.

5 0
3 years ago
A(n) key is the set of steps used to convert an unencrypted message into an encrypted sequence of bits that represent the messag
a_sh-v [17]

Answer:

Algorithm

Explanation:

Algorithm is a set of instructions designed to perform a specific task, an independent sequence of actions to be perform to solve a problem and instruction for performing a computation.

Algorithm is A(n) key set of steps used to convert an unencrypted message into an encrypted sequence of bits that represent the message; it sometimes refers to the programs that enable the cryptographic processes.

5 0
3 years ago
Read 2 more answers
Other questions:
  • In Java :
    11·1 answer
  • Which type of communication protocol converts data into standard formats that can be used by applications?
    11·1 answer
  • A firewall, when properly implemented, can prevent most attacks on your system.
    11·1 answer
  • John's Plumbing prides itself on excellent customer service, especially during after-hours service calls. They want to connect w
    11·1 answer
  • Heelp my brainly stuff says i am 49 but im 11 how to fix?X??
    7·1 answer
  • Which words in the sentence make up the adjective phrase? Which word does the adjective phrase modify? The farmer delivers five
    15·1 answer
  • An mp3 takes up about 16 kilobytes of memory per second of music. if you owned a one terabyte hard drive and filled it with only
    15·1 answer
  • Help please! Coding!
    9·1 answer
  • Which of the following represents something businesses do to keep the integrity and security of their company data?
    13·1 answer
  • Which of the following are the most important reasons people in the 1920s were so interested in seeing lifelike stories in audio
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!