Sort Books By Price
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static Book[] sortBooksByPrice(Book[] b){
int n = b.length;
for(int i =0; i<n; i++){
for(int j=i+1; j<n; j++){
if(b[i].price > b[j].price){
Book temp = b[i];
b[i] = b[j];
b[j] = temp;
return b;
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Book[] b1 = new Book[4];
Scanner sc = new Scanner(System.in);
for(int i=0;i<4;i++)
{
int id = sc.nextInt();
sc.nextLine();
String title = sc.nextLine();
String author = sc.nextLine();
double price = Double.parseDouble(sc.next());
b1[i]= new Book(id,title,author,price);
Book[] result = sortBooksByPrice(b1);
for(int i=0;i<4;i++){
System.out.println(result[i].id+" "+result[i].title+" "+result[i].author+" "+result[i].price);
class Book
int id;
String title, author;
double price;
Book(int id, String title, String author, double price){
this.id = id;
this.title = title;
this.author= author;
this.price = price;
}
public int GetId(){
return this.id;
public String GetTitle(){
return this.title;
public String GetAuthor() {
return this.author;
public double GetPrice() {
return this.price;
public void SetId(int x){
this.id =x;
public void SetTitle(String x){
this.title =x;
public void SetAuthor(String x){
this.author =x;
public void SetPrice(double x){
this.price =x;
Prime number check
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static boolean isPrime(int n){
if(n<=1)
return false;
for(int i=2; i < Math.sqrt(n); i++){
if(n%i==0)
return false;
return true;
public static int reverseOf(int n){
return Integer.parseInt(new StringBuilder(Integer.toString(n)).reverse().toString());
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] a = new int[100];
for(int i =0; i<n; i++){
a[i] = sc.nextInt();
}
int list[] = new int[100];
int j=0;
for(int i=0;i<n;i++){
if(isPrime(a[i]) && isPrime(reverseOf(a[i])))
list[j++]= a[i];
for(int i=0; i<j; i++){
for(int k=i+1; k<j; k++){
if(list[i]>list[k]){
int temp = list[k];
list[k]=list[i];
list[i]=temp;
for(int i=0; i<j; i++){
System.out.println(list[i]);
Students From Same City and Same Marks
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static Student[] getStudentsWithCityAndMarks(Student[] s, String city, double marks){
int n = s.length;
int count=0;
for(int i=0;i<n;i++){
if(s[i].city.equals(city) && s[i].marks==marks)
count++;
Student result[] = new Student[count];
for(int i=0,j=0;i<n;i++){
if(s[i].city.equals(city) && s[i].marks==marks)
result[j++]=s[i];
for(int i=0;i<count;i++)
for(int j=i+1;j<count;j++){
if(result[i].id>result[j].id){
Student temp = result[i];
result[i]=result[j];
result[j]=temp;
return result;
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.next());
Student [] s1 = new Student[n];
for(int i=0; i<n; i++){
s1[i]=new Student(Integer.parseInt(sc.next()),sc.next(),sc.next(),Double.parseDouble(sc.next()));
Student[] result = getStudentsWithCityAndMarks(s1, sc.next(), Double.parseDouble(sc.next()));
int count= result.length;
System.out.println(count);
for(int i=0; i<count; i++){
System.out.println(result[i].id+" "+result[i].name+" "+result[i].city+" "+result[i].marks);
class Student {
int id;
String name;
String city;
double marks;
Student(int id, String name, String city, double marks){
this.id = id;
this.name = name;
this.city = city;
this.marks = marks;
public int GetId(){
return this.id;
public String GetName(){
return this.name;
public String GetCity(){
return this.city;
public double GetMarks(){
return this.marks;
public void SetId(int x){
this.id = x;
public void SetName(String x) {
this.name = x;
public void SetCity(String x) {
this.city = x;
public void SetMarks(double x) {
this.marks = x;
TCS Xplore Java10 - Return vowel string
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc = new Scanner(System.in);
String input = sc.next();
input = input.toLowerCase();
String output ="";
for(int i=0; i< input.length(); i++){
if(input.charAt(i)=='a')
output += 'a';
if (input.charAt(i) == 'e')
output += 'e';
if (input.charAt(i) == 'i')
output += 'i';
if (input.charAt(i) == 'o')
output += 'o';
if (input.charAt(i) == 'u')
output += 'u';
System.out.print(output);