Question

Write a program for IJVM called scramble that takes lowercase text from input and prints the...

Write a program for IJVM called scramble that takes lowercase text from input and prints the next character (i.e. ‘b’ is printed as ‘c’) and uppercase text and prints the character before (‘B’ is printed as ‘A’). Print all other characters as is.

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

Complete Program:

import java.util.Scanner;

class IJvm {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

char ch, c, choice = 'k';

do {

System.out.println("Enter one character ");

c = sc.next().charAt(0);

int ascii = (int) c;

if (ascii >= 65 && ascii <= 122) {

if (Character.isLowerCase(c)) {

if (ascii == 122)

ascii = (int) 'a';

else

ascii = ascii + 1;

} else {

if (ascii == 65)

ascii = (int) 'Z';

else

ascii = ascii - 1;

}

System.out.println((char) (ascii));

} else {

System.out.println("Invalid input!!");

}

System.out.print("Do you want to enter one more character (y/n): ");

choice = sc.next().charAt(0);

} while (choice == 'y' || choice == 'Y');

}

}

Screenshots:

Add a comment
Know the answer?
Add Answer to:
Write a program for IJVM called scramble that takes lowercase text from input and prints the...
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
  • IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption...

    IN PYTHON Implement a function easyCrypto() that takes as input a string and prints its encryption defined as follows: Every character at an odd position i in the alphabet will be encrypted with the character at position i + 1, and every character at an even position i will be encrypted with the character at position i - 1. In other words, ‘a’ is encrypted with ‘b’, ‘b’ with ‘a’, ‘c’ with ‘d’, ‘d’, with ‘c’, and so on. Lowercase...

  • Write a program that takes in a line of text as input, and outputs that line...

    Write a program that takes in a line of text as input, and outputs that line of text in reverse. You may assume that each line of text will not exceed 50 characters. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH уен Hint: Use the fgets function to read a string with spaces from the user...

  • in Python: •Flip case: Write a program to do the following: •Accept the input of a...

    in Python: •Flip case: Write a program to do the following: •Accept the input of a sentence from the user that contains lowercase, uppercase, and special characters. •Make a new sentence in which the lowercase characters are changed to uppercase and the uppercase are changed to lower case.   All other characters will retain their original value. Print the original sentence and the new sentence.

  • Write a c program that takes in a text file and writes lines with only lowercase...

    Write a c program that takes in a text file and writes lines with only lowercase letters to another text file which is disclosed from the command line. If no text file to output to is disclosed in the command line, the lines with only lowercase letters should be written into a text file called "all_lower.txt"

  • Part I) Write a program that copies one file to another, replacing all lowercase characters with...

    Part I) Write a program that copies one file to another, replacing all lowercase characters with their uppercase equivalents. Part II) Write a program that merges lines alternately from two files and writes the results to a third file. If one file has less lines than the other, then the remaining lines from the larger file should be printed to the screen. Using C language

  • Write a C program that prompts the user for an input string with all lowercase letters....

    Write a C program that prompts the user for an input string with all lowercase letters. Your program should then sort the characters in the string and print the sorted string. Assume that the string contains no spaces and has at most 30 lowercase characters. Your program should loop continually until the user enters “q” to quit.

  • Can you write a program to convert a string from uppercase to lowercase and lowercase to...

    Can you write a program to convert a string from uppercase to lowercase and lowercase to uppercase depending on the user's input? In simple C++ please So for example if the input is Hello then the output should be hELLO

  • You're to write a C++ program that analyzes the contents of an external file called data.txt....

    You're to write a C++ program that analyzes the contents of an external file called data.txt. (You can create this file yourself using nano, that produces a simple ASCII text file.) The program you write will open data.txt, look at its contents and determine the number of uppercase, lowercase, digit, punctuation and whitespace characters contained in the file so that the caller can report the results to stdout. Additionally, the function will return the total number of characters read to...

  • Write a C program named space_to_line.c that features a while loop that continuously reads input from...

    Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...

  • General Requirements . . . Write a program that reads letters from a file called "letters.txt"....

    General Requirements . . . Write a program that reads letters from a file called "letters.txt". Your program will open the letters.txt file read in one character at a time For this assignment the test file will contain at least 30 letters, uppercase OR lowercase In your program you will change each letter (solution) to uppercase Use the function toupper in #include <ctype.h> You create a numerical version of the uppercase letter from the file . o Use int numberSolution...

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