Bob
Bob
import java.util.Scanner;
VDT:
Ans:
OUTPUT:
VDT:
ANS:
class pattern
{
public static void main(String[] args)
{
int n = 4;
for(int i = 0 ; i <= n ; i++)
{
for(int j = 0 ; j <= i ; j++)
{
System.out.print(" "+(char)(65 + i));
}
System.out.println("");
}
}
}
OUTPUT:
VDT:
Write a main method to create an object of the class and call the above member
methods.
ANS:
import java.util.Scanner;
OUTPUT:
VDT:
16.
Define a class Salary with the following specifications:
Class name : Salary
Data members : Name, Address, Phone, Subject, Specialization, Monthly Salary,
income tax.
Member methods:
(i) to accept the details of a teacher including the monthly salary
(ii) to compute the annual income tax at 5% of the annual salary exceeding₹
1,75,000.
(iii) to display the details of the teacher.
Write a main method to create object of the class and call the above member
methods.
[ICSE 2007].
ANS:
class Salary
{
String Name;
String Address;
int Phone;
String SubjectSpecialization;
float MonthlySalary;
float IncomeTax;
OUTPUT:
VDT:
ANS:
import java.util.Scanner;
int uc =0;
int lc =0;
int sc =0;
int dc =0;
char ch;
for (int i = 0; i < len; i++)
{
ch = str.charAt(i);
if (Character.isUpperCase(ch))
uc++;
else if (Character.isLowerCase(ch))
lc++;
else if (Character.isDigit(ch))
dc++;
else if (!Character.isWhitespace(ch))
sc++;
}
}
}
OUTPUT:
VDT:
18.Write a program to accept a name and display the initials along with the
surname.
Sample Input: Mohandas Karamchand Gandhi
Sample Output: M. K. Gandhi.
ANS:
import java.util.Scanner;
/*
* Get the last index
* of space in the string
*/
int lastSpaceIdx = name.lastIndexOf(' ');
OUTPUT:
VDT:
19.A string is said to be Unique, if none of the letters present in the string are
repeated. Write a program to accept a string and check whether the string is Unique
or not. The program displays a message accordingly.
Sample Input: COMPUTER
Sample Output: Unique String.
ANS:
import java.util.Scanner;
char ch = str.charAt(i);
if (!isUnique)
break;
}
if (isUnique)
System.out.println("Unique String");
else
System.out.println("Not Unique String");
}
}
OUTPUT:
VDT:
ANS:
import java.util.Scanner;
if (!found) {
System.out.println("Name not found.");
}
scanner.close();
}
}
OUTPUT:
VDT: