Question

Create a Java program that uses the concepts below:   String myName = "Rick";     int length...

Create a Java program that uses the concepts below:

  String myName = "Rick";

    int length = myName.length();

    char firstChar = myName.charAt(0);

    char secondChar = myName.charAt(1);

    if (myName.equals("Jerry")) {

      System.out.println ("Don't be a Jerry");

  }

Write a program that uses a METHOD to translate numbers (1-10) into their verbal counterparts.

ex: 1 would be translated into "one"

DO NOT use arrays or subStrings for this task!!!

Sample output:

Enter a String: 123

one two three

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

CODE

import java.util.Scanner;

public class Main {

public static void printDigit(int n) {

switch(n) {

case 0:

System.out.print("one ");

break;

case 1:

System.out.print("two ");

break;

case 2:

System.out.print("three ");

break;

case 3:

System.out.print("four ");

break;

case 4:

System.out.print("five ");

break;

case 5:

System.out.print("six ");

break;

case 6:

System.out.print("seven ");

break;

case 7:

System.out.print("eight");

break;

case 8:

System.out.print("nine ");

break;

case 9:

System.out.print("ten ");

break;

default:

throw new IllegalArgumentException();

}

}

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String str;

System.out.print("Enter a string: ");

str = sc.nextLine();

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

char ch = str.charAt(i);

printDigit(ch - '1');

}

}

}

Add a comment
Know the answer?
Add Answer to:
Create a Java program that uses the concepts below:   String myName = "Rick";     int length...
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
  • Spell it out! Use the following Java concepts to compile the program below:   String myName =...

    Spell it out! Use the following Java concepts to compile the program below:   String myName = "Chuck";     int length = myName.length();     char firstChar = myName.charAt(0);     char secondChar = myName.charAt(1);     if (myName.equals("Tom")) {       System.out.println ("Sorry, Tom!");   } Write a program that uses a METHOD to translate these individual characters:   input output input output input output input output input output a 4 g 9 m /\\/\\ s $ y ‘/ b B h |-| n |\\| t...

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • in java Part 1 In this section, we relook at the main method by examining passing...

    in java Part 1 In this section, we relook at the main method by examining passing array as parameters. Often we include options/flags when running programs. On command line, for example, we may do “java MyProgram -a -v". Depending on options, the program may do things differently. For example, "a" may do all things while "-v" display messages verbosely. You can provide options in Eclipse instead of command line: "Run ... Run Configurations ... Arguments". Create a Java class (Main.java)....

  • In this same program I need to create a new method called “int findItem(String[] shoppingList, String...

    In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...

  • use java program, create a class with conditions below. 1. asking user to type int number...

    use java program, create a class with conditions below. 1. asking user to type int number 2.you have to receive it use next String (not next int) 3.use try catch , if user input is not int, ask them to retype int number. (have to print out message that said only type int number)

  • FOR JAVA: Summary: Create a program that adds students to the class list (see below). The...

    FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...

  • This is for a java program public class Calculation {    public static void main(String[] args)...

    This is for a java program public class Calculation {    public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object    //Task 1. Write your code here //Print the prompt and ask the user to enter an...

  • Write a Java program for all items in Question Use System.out.println() for each resulting string. Let...

    Write a Java program for all items in Question Use System.out.println() for each resulting string. Let s1 be " Welcome " and s2 be " welcome ". Write the code for the following statements: a. Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual. b. Check whether s1 is equal to s2, ignoring case, and assign the result to a Boolean variable isEqual. c. Compare s1 with s2 and assign the result to...

  • Write the following Java program: public static String getFlag(int size, char color1, char color2, char color3)...

    Write the following Java program: public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y'); will generate the string: R............................................ RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRR.................................... RRRRRRRRR.................................... RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY R............................................ The diagram has a number of rows that corresponds to size * 2 and...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

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
ADVERTISEMENT