Deliverables: For this assignment, you are required to submit 2 pieces of work 1
ID: 3730736 • Letter: D
Question
Deliverables: For this assignment, you are required to submit 2 pieces of work 1. Java file containing your program(70%) 2. A flow chart to show your design of the program(30%) Learning Outcomes 1. 2. 3. Solve programming problems of modest complexity in a systematic, well- organised way Specify precisely the syntax and semantics of a programming language construct Select an appropriate program construct (or datatype) to achieve a given task Document accurately the design of a program on-the-fly 4. Grading Outline Input-5% Output= 5% String processing-25% Word reversing-20% Use of methods 15% Check to see if reverse is possible = 5% Check for anagram 5% Check for pangram Structure and neatness of code = 15% · · . . 0Explanation / Answer
Program
package revstr;
import java.io.*;
public class Revstr {
public static final int m = 26;
public static void main(String[] args)throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter string: ");
String s = br.readLine();
System.out.print("Enter n : ");
int n = Integer.parseInt(br.readLine());
reverseNthWordOfString(s,n); //Reverse nth word of string
check(s); //Check for anagram
}
static void reverseNthWordOfString(String inputString,int n)
{
String palString;
String[] words = inputString.split(" ");
String reverseString = "";
if(words.length<n)
{
System.out.println("Not possible to reverse!!!");
System.out.println("Input n is greater than number of words in the sentence ");
}
else
{
for (int i = 0; i < words.length; i++)
{
String word = words[i];
String reverseWord = "";
if(i==n-1)
{
palString=words[i];
n+=n;
for (int j = word.length()-1; j >= 0; j--)
{
reverseWord = reverseWord + word.charAt(j);
}
words[i]=" ";
if(reverseWord.equals(palString))
{
System.out.println("The word "+reverseWord+" is palindrome");
}
}
reverseString = reverseString + words[i] +reverseWord+ " ";
}
System.out.println(inputString);
System.out.println(reverseString);
System.out.println("-------------------------");
}
}
static void check(String arr)
{
int d = 0;
if(arr.length() < m){
d= -1;
}
for(char c = 'A'; c <= 'Z' ; c++)
{
if((arr.indexOf(c) < 0) && (arr.indexOf((char)(c + 32)) < 0))
{
d=-1;
}
}
d= 1;
if(d == -1)
System.out.println("Given sentence is not pangram");
else
System.out.print(" Given sentence is pangram");
}
}
Output
Enter string: We promptly judged antique ivory buckles for the next prize
Enter n : 3
We promptly judged antique ivory buckles for the next prize
We promptly degduj antique ivory selkcub for the next prize
-------------------------
Given sentence is pangram
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.