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
zhannawk [14.2K]
3 years ago
7

1) A String variable , fullName, contains a name in one of two formats:

Computers and Technology
2 answers:
natulia [17]3 years ago
7 0

Answer:

// Scanner class is defined to allow the program receive user input

import java.util.Scanner;

// The class name Solution is defined

public class Solution {

   // object stdin of Scanner is declared static and private

   // it is static

   // so that it can be called from questionTwo method

   private static Scanner stdin = new Scanner(System.in);

   // main method to begin program execution

   public static void main(String args[]) {

       // prompt the user to enter full name

       System.out.println("Enter the fullname: ");

       // the received name is saved to userInput

       String userInput = stdin.nextLine();

       // empty string for firstName

       String firstName = "";

       // empty string for lastName

       String lastName = "";

       

       // if the userInput contain comma

       // then it is splitted with comma

       // else if it doesn't contain comma

       // it is splitted with space

       if(userInput.contains(",")){

           String[] array = userInput.split(",");

           // lastName is the name before the comma

           lastName = array[0];

           // firstName is the name after the comma

           firstName = array[1];

       } else{

           String[] array = userInput.split(" ");

           // firstName is the name before the space

           firstName = array[0];

           // lastName is the name after the space

           lastName = array[1];

       }

       // firstName and last is printed

       System.out.println("FirstName: " + firstName + "\nLastName: " + lastName);

       

       // beginning of second part of question

       // method for questionTwo is called

       questionTwo();

   }

   

   // solution to questionTwo

   public static void questionTwo(){

       // the userword is declared as empty string

       String userword = "";

       // landCounter is set to 0

       int landCounter = 0;

       // airCounter is set to 0

       int airCounter = 0;

       // waterCounter is set to 0

       int waterCounter = 0;

       // while to continue receiving user input

       // as long as it is not "xxxxx"

       while(true) {

           // The user is prompt to enter a word

           System.out.println("Enter your word again: ");

           // the received word is saved to userword

           userword = stdin.nextLine();

           /* Block of if-statement to increment

           counter based on the input value of userword

           if userword is "xxxxx", the loop terminate

           */

           if(userword.equals("land")){

               landCounter += 1;

           }

           if(userword.equals("air")){

               airCounter += 1;

           }

           if(userword.equals("water")){

               waterCounter += 1;

           }

           if (userword.equals("xxxxx")){

               break;

           }

       }

       // Display the number of land, air and water in three lines

       System.out.println("land: " + landCounter + "\nair: " + airCounter + "\nwater: " + waterCounter);

   }

}

Explanation:

The code is well commented. There is an attach image of when the code is executed.

ivolga24 [154]3 years ago
6 0

Answer:

1)

if (fullName.indexOf(", ") != -1){

 lastName = fullName.substring(0, fullName.indexOf(", "));

 firstName = fullName.substring(fullName.indexOf(", ") + 2, fullName.length());}

else{

 firstName = fullName.substring(0, fullName.indexOf(" "));

 lastName = fullName.substring(fullName.indexOf(" ") + 1, fullName.length());}

Explanation:

fullName is a string that contains the full name.

This string is to be split into two sub strings containing last and first name. indexOf() function is used which returns the position of the specified character in this function like here the specified character is comma followed by a space (, ) or single space( ).

+2 means that it will skip the comma/single space from the fullName string to store the string in the lastName.

length() function here is used to return the number of characters in the string fullName.

!= -1 here checks if the comma or space are present in the fullName string.

Another way to extract first and last name from full  name is:

int index = fullName.indexOf(",");

if (index >= 0){

lastName = fullName.substring(0, index).trim();

firstName = fullName.substring(index+1).trim();}

else

{index = fullName.indexOf(" ");

firstName = fullName.substring(0, index).trim();

lastName = fullName.substring(index+1).trim();}

trim() function here removes the spaces.

The fullName can be assigned a name like this:

String fullName="lastname, firstname";

To display sub strings:

System.out.println(lastName);

System.out.print(firstName);

2)

String userstring= ""; // store the string

int land = 0;  

int air = 0;

int water = 0;

while(!(userstring.equals("xxxxx"))) {  //  loop terminates when "xxxxx"  is read

userstring = stdin.next();  // reads the string of characters

if(userstring.equals("land")) {

/* equals functions compares the entered string with land specified in this function */

   land= land + 1;  

}else if(userstring.equals("air")) {

   air= air + 1;

}else if(userstring.equals("water")) {

   water = water + 1;

}  }

//displays land air and water on a separate line

System.out.println("land:" + land);

System.out.println("air:" + air);

System.out.println("water:" + water);

You might be interested in
Application for a lawn-mowing service. The lawn-mowing season lasts 20 weeks. The weekly fee for mowing a lot under 40 square fe
Alex

The prompt to the user for the length and width of a lawn is; Done by the program created below in Java using JOPTIONPANE

<h3>How do you write a Program in Java?</h3>

// library

import java.util.*;

// class definition

class Main

{// main method of the class

public static void main (String[] args) throws java.lang.Exception

{

  try{

   // object to read inputs

     Scanner scr=new Scanner(System.in);

     System.out.print("Enter length of lawn:");

     // read the length of lawn

     int length=scr.nextInt();

     System.out.print("Enter width of lawn:");

     // read the width of lawn

     int width=scr.nextInt();

     // find area of lawn

     int area=length*width;

     //if area is less than 400

     if(area<400)

     {// Weekly mowing fee

         System.out.println("Weekly mowing fee is:$25");

         // seasonal fee

         System.out.println("20-week seasonal fee is:$"+(25*20));

     }

     // if area >=400 and area <600

     else if(area>=400 && area<600)

     {

        // Weekly mowing fee

         System.out.println("Weekly mowing fee is:$35");

         // seasonal fee

         System.out.println("20-week seasonal fee is:$"+(35*20));

     }

     // if area >=600

     else if(area>=600)

     {

        // Weekly mowing fee

         System.out.println("Weekly mowing fee is:$50");

         // seasonal fee

         System.out.println("20-week seasonal fee is:$"+(50*20));

     }

  }catch(Exception ex){

      return;}

}

}

Read more about Java Programming at; brainly.com/question/18554491

3 0
2 years ago
in a typical e-mail address, the "host" is A. an account designated by a user name B. CPU processor 2500 C. the receiver of an e
NISA [10]
The correct answer is A! :)
5 0
3 years ago
Read 2 more answers
Supervisor: You will need to consolidate your trouble tickets
liubo4ka [24]
Wheres the rest???????????????????
7 0
3 years ago
1. (15%) Consider a computer system with three users: Alice, Bob, and Cyndy. Alice owns the file a, and Bob and Cyndy can read i
Fantom [35]

Answer:

answered in Image and explanation is given below.

Explanation:

CL is euqal to user permission on every file

ACL is equal to how permissions are defined for one life for example File a, read, write, execute.

4 0
3 years ago
Why can videos be streamed from the cloud to a computer with no loss in
mezya [45]
I think the answer is B
3 0
3 years ago
Read 2 more answers
Other questions:
  • Determine the value of base x of (211)x=(152)8
    8·2 answers
  • When typing in a cell, hitting Tab will bring which result?
    12·2 answers
  • Select the correct answer.
    8·1 answer
  • E-mail is an temporary message medium.<br> a. True<br> b. False
    5·2 answers
  • Assume that the following variables have been defined in a program: int x = 10; int y = 20; int z = 30; Write a cout statement t
    11·1 answer
  • What should I do if I pluged in my computer charger and it starts making noise and sounds? Plz tell me. Will mark as brainliest
    6·1 answer
  • A museum is evaluating historical documents for authenticity, reviewing their physical condition, and categorizing them by subje
    9·1 answer
  • How many times will it tack when you fill 1 - liter of jar with water from the pond and uses 100 - milliliter cup to scoop water
    12·1 answer
  • Write a python program to print numbers from 100 to 50 using for loop.<br> I NEED THIS URGENT PLEASE
    9·1 answer
  • Choose the answer that best completes the visual analogy.
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!