Page 541 - Cs_withBlue_J_C11_Flipbook
P. 541
The output of the preceding program is as follows:
Enter a number: 546
546 is a Bouncy Number.
Variable Description
NAME TYPE DESCRIPTION
num int Number to be taken
before int Contains previous value
rem int To store Remainder
temp int Temporary variable
incre boolean Check if sorted in ascending order
decre boolean Check if sorted in descending order
Program 21 Write a program in Java to accept a string and display the new string after reversing the
characters of each word.
Sample Input:
Understanding Computer Science
Sample output:
gnidnatsrednU retupmoC ecneicS
class name : strrev
Data Members
String str : Stores the original String
String nwstr : Stores the new String
int len : Length of the String
Member Methods
void input() : Inputs the new String in "str"
void reverse() : Reverses the string in "nwstr"
void display() : Prints both the strings
1 import java.util.*;
2 class strrev
3 {
4 String str,nwstr;
5 void input()
6 {
7 int len;
8 Scanner sc = new Scanner(System.in);
9 System.out.println("Enter a string:");
10 str = sc.nextLine();
11 len=str.length();
539
Internal Assessment 539

