Question

1. Creatc a lava program thal asks the user to cnter his/her first name and last namc, in a single linc and separaled by a spacc. The program should output separately the first namc and the last name. (Use the Scanner class.) 2. Create a Java program thal asks the user for a medium (air, water or sleel), and outputs the speed of sound in thal medium (1 100 feclsec in air, 4900 feesec in water and 16,400 feet sec in steel). Use the Scanner class to read the input and a switch statement to implement the decision structure. 3. Create a Java program that formats the number 123456789.1234567890 using the DecimalFormat class and the printfmcthod as: 123456789.1 123,456,789.12 123,456,789.123 4. Create a Java program that asks for the names of three runners and the time, in minutes, it took each of then to finish a race. The program should display the names of the runn ers in the order they finished. 5. Create a lava application that asks a user o enter the namc of a menu ilem, the number olf gras f at, the number of gras of procin, and the numbcr of grams of carbohydrates the item contains. The program should display the total number of calories in the item, as well as the percent of calories that come from fat. Use the following information to perform the calculations. I gram fat=9 calories; I gram carbohydrate-4 calories; I gram protein 4 calories A bank charges a base fec ofS10 per month, plus the following chcck fees for a commercial banking account: 6. S.10 each for less than 20 checks $.08 cach for 20-39 checks S.06 cach 40-59 checks S.04 each for 60 or more checks Create a Java application that asks for the number of checks written for the month. The application should then calculate and display the banks services tees for the month.

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

if you post more than question, as per HomeworkLib guideliens we have to solve only first question.

Ques 1.

import java.util.*;

public class Solution

{

    public static void main(String[] args)

    {

        // create a Scanner class object to get user input

        Scanner sc = new Scanner(System.in);

       

        System.out.print("Enter first name and last name seprated by space : ");

       

        // read complete line using nextLine()

        String name = sc.nextLine();

       

        // split the string using split() function wuth space as delimeter

        // arr[0] sores first name

        // arr[1] sores last name

        String[] arr = name.split(" ");

       

        String fname = arr[0];

        String lname = arr[1];

       

        System.out.println("\nFirst Name : " + fname);

        System.out.println("Last Name : " + lname);

    }

}

Sample Output

Add a comment
Know the answer?
Add Answer to:
1. Creatc a lava program thal asks the user to cnter his/her first name and last...
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
  • Write a Python program that asks the user to enter the number of calories and fat...

    Write a Python program that asks the user to enter the number of calories and fat grams in a food item. The program should display the percentage of the calories that come from fat. One gram of fat has 9 calories, therefore: Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as follows: Calories from fat / total calories If the calories from fat are less than 30 percent of the total...

  • ***** JAVA ONLY ***** Write a program that asks the user to enter the name of...

    ***** JAVA ONLY ***** Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Use Notepad to create a simple file that can be used to test the program. ***** JAVA ONLY *****

  • Create a program that asks that asks the user for the number of males and females...

    Create a program that asks that asks the user for the number of males and females in a class. The program should display a percentage of males and females. For example, there are 5 males, and 15 females. That makes 20 people total. To find the percentage of males you can divide 5 by 20, which makes 0.25, or 25% HINT: USE A VARIABLE for every group of people that you will use in your calculation. Submit your .java source...

  • Create a Java program which asks the user how many names they want to enter. The...

    Create a Java program which asks the user how many names they want to enter. The program should then instantiate an array that will hold this many names. The main method should call a method, getNames() to allow the user to enter the names. A for loop should be used in this method. Once the names are entered, the main method should call another method displayNames() which will use a while loop to display the names entered.

  • In Java, write a program that asks the user for the name of a file. The...

    In Java, write a program that asks the user for the name of a file. The program should read all the numbers from the given file and display the total and average of all numbers in the following format (three decimal digits): Total: nnnnn.nnn Average: nnnnn.nnn Class name: FileTotalAndAverage

  • Write a program that asks the user for his or her name, and then asks the user to enter a sentence that describes him or herself.

    23. Personal Weeb Page GeneratorWrite a program that asks the user for his or her name, and then asks the user to enter a sentence that describes him or herself. Here is an example of the program's screen:Enter your name: Julie Taylor [Enter]<html>  <head>  </head>  <body>    <center>      <h1>Julie Taylor</h1>    </center>    <hr />    I am a computer science major, a member of the Jazz club,    and I hope to work as a mobile app developer after I graduate.    <hr />  </body> </html>Describe yourself: I am a computer science major, a member of theOnce the user has entered the requested input, the program should create an HTML file,...

  • Write a java program that asks the user to enter an integer. The program should then...

    Write a java program that asks the user to enter an integer. The program should then print all squares less than the number entered by the user. For example, if the user enters 120, the program should display 0, 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

  • Java Q6 Part 6 Write a program with the class name BoxMaker that asks the user...

    Java Q6 Part 6 Write a program with the class name BoxMaker that asks the user for an integer x (using Scanner), and then builds a box ofx asterisks. For example, if x = 4, then your output would be: // inner body " ": x - numLids ("*" on each side) == x - 2

  • RandomGame.cpp (2pt) Write a program that asks the user to enter his/her name. Then begin a...

    RandomGame.cpp (2pt) Write a program that asks the user to enter his/her name. Then begin a do while loop that asks the user to enter a number between 1 and 10. Have the random number generator produce a number 1 and 10. Display the user’s name and both numbers to the screen. Compare the two numbers and report if the entered number is greater than, less than, or the same as the generated number. Ask the user if he/she’d like...

  • Write a program that asks the user to input the number of males and females registered...

    Write a program that asks the user to input the number of males and females registered in a class (Max 30 members in the class). The program should display the percentage of males and females in the class. Python programming question

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