Professional Documents
Culture Documents
JAva
JAva
import java.util.Scanner;
class Account {
private int id;
}
public static double calculateInterest(Account a , int noOfYears) {
double result =noOfYears*a.getInterestRate()/100;
return (a.getBalance()*(a.getInterestRate()+result)/100);
}
}
Distance From Origin :
import java.util.Scanner;
class Solution {
public static void main (String [] args) {
Scanner in =new Scanner(System.in);
int x1=in.nextInt();
int y1=in.nextInt();
int x2=in.nextInt();
int y2=in.nextInt();
int x3=in.nextInt();
int y3=in.nextInt();
Point p1 = new Point(x1,y1);
Point p2=new Point(x2,y2);
Point p3=new Point(x3,y3);
Point high = highestPoint(p1,p2,p3);
}
public static Point highestPoint(Point p1, Point p2, Point p3) {
double d1=Math.sqrt((p1.x*p1.x)+(p1.y*p1.y));
double d2 =Math.sqrt((p2.x*p2.x)+(p2.y)*(p2.y));
double d3 =Math.sqrt((p3.x*p3.x)+(p3.y)*(p3.y));
return (d1>d2)?((d1>d3)?p1:p3):(d2>d3?p2:p3);
}
}
class Point{
double x;
double y;
Point(double x , double y){
this.x=x;
this.y=y;
}
}
import java.util.Scanner;
class Solution {
public static void main(String [] args) {
Scanner in =new Scanner(System.in) ;
int x1=in.nextInt();
int x2=in.nextInt();
int y1=in.nextInt();
int y2=in.nextInt();
Point p1=new Point(x1,y1);
Point p2=new Point(x2,y2);
double distance = findDistance(p1,p2);
System.out.printf("%.3f",distance);
}
public static double findDistance(Point p1, Point p2) {
double distance =Math.sqrt(Math.pow((p2.x-p1.x),2)+Math.pow((p2.y-
p1.y),2));
return distance;
}
}
class Point {
int x;
int y;
Point(int x,int y){
this.x=x;
this.y=y;
}
Min Alphabet :
import java.util.Scanner;
class Solution{
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
String str= in.nextLine();
char min = str.charAt(0);
for(int i =0;i<str.length();i++) {
if((int)str.charAt(i)< (int)min) {
min=str.charAt(i);
}
}
System.out.println(min);
}
}
Factorial :
import java.util.Scanner;
class Solution{
public static void main(String []args ) {
Scanner in =new Scanner(System.in);
int [] result = new int[5];
for(int i=0 ; i<5;i++) {
int num=in.nextInt();
result[i]=factorial(num);
}
for(int i : result) {
System.out.println(i);
}
}
import java.util.*;
class Document {
private int id;
private String title;
private String folderName;
private int pages;
this.id = id;
this.title = title;
this.folderName = folderName;
this.pages = pages;
}
int j=0;
int count=0;
for(int i=0; i<4;i++) {
if(obj[i].getPages()%2 != 0) {
count++;
}
}
Document[] doc =new Document[count];
}
public static void main(String [] args) {
Scanner in =new Scanner(System.in);
Document [] obj = new Document[4];
for(int i =0;i<4;i++) {
int id =in.nextInt();
in.nextLine();
String title =in.nextLine();
String folderName=in.nextLine();
int pages=in.nextInt();
obj[i]=new Document(id,title,folderName,pages);
}
Document[] obj1 =docsWithOddPages(obj);
for(Document d : obj1) {
if(d != null){
System.out.println(d.getId()+" "+d.getTitle()+" "+d.getFolderName()+"
"+d.getPages());
}
}
}
}
import java.util.Scanner;
class Book {
this.id = id;
this.title = title;
this.author = author;
this.price = price;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
class Solution {
public static Book[] sortBooksByPrice(Book[] obj) {
for(int i=0;i<4;i++) {
for(int j=i+1;j<4;j++) {
if(obj[i].getPrice() > obj[j].getPrice()) {
Book temp = obj[i];
obj[i]=obj[j];
obj[j]=temp;
}
}
}
return obj;
}
public static void main(String [] args) {
Scanner in = new Scanner(System.in);
Book [] obj = new Book[4];
for(int i=0 ;i<4;i++) {
int id =in.nextInt();
in.nextLine();
String title =in.nextLine();
String author=in.nextLine();
double price =in.nextDouble();
obj[i]=new Book(id,title,author,price);
}
}
import java.util.Scanner;
class Book {
private int id;
private String title;
private String author;
private double price;
}
class Solution{
int j=0;
int count=0;
for(int i=0;i<4;i++) {
if(obj[i].getTitle().toLowerCase().contains(key)) {
count++;
}
}
Book[] obj1 = new Book[count];
for(int i =0;i<4;i++) {
if(obj[i].getTitle().toLowerCase().contains(key)) {
obj1[j++]=obj[i];
}
}
for(int i =0;i<obj1.length;i++) {
for(int k=i+1;k<obj1.length;k++) {
if(obj1[i].getId()>obj[k].getId()) {
Book temp=obj1[i];
obj1[i]=obj1[k];
obj1[k]=temp;
}
}
}
return obj1;
}
public static void main(String [] args) {
Scanner in =new Scanner(System.in);
Book [] obj=new Book[4];
for(int i=0;i<4;i++) {
int id=in.nextInt();
in.nextLine();
String title =in.nextLine();
String author =in.nextLine();
double price =in.nextDouble();
import java.util.Scanner;
for(int i = 0;i<5;i++)
{
int tag = sc.nextInt();sc.nextLine();
String brand = sc.nextLine();
double price = sc.nextDouble();sc.nextLine();
char g = sc.nextLine().charAt(0);
shirts[i] = new Shirt(tag,brand,price,g);
}
for(Shirt s: shirts)
{
System.out.println(getDiscountPrice(s));
}
for(Shirt s: result)
{
System.out.println(s.getTag()+" "+s.getPrice()+ " " + s.getBrand());
}
}
return s.getPrice()-(discount*s.getPrice())/100;
}
public static Shirt[] getShirtWithMoreThanSpecificPrice(Shirt[] shirts , double
price){
int size=0;
for(int i =0 ;i<shirts.length;i++){
if(shirts[i].getPrice() > price){
size++;
}
}
Shirt [] obj = new Shirt[size];
int j=0;
for(int i =0 ;i<shirts.length;i++){
if(shirts[i].getPrice() > price){
obj[j++]=shirts[i];
}
}
for(int i=0;i<size;i++){
for(int k=i+1;k<size;k++){
if(obj[i].getPrice()>obj[k].getPrice()){
Shirt temp = obj[i];
obj[i]=obj[k];
obj[k]=temp;
}
}
}
return obj;
}
}
class Shirt
{
private int tag;
private String brand;
private double price;
private char gender;
Shirt(int tag, String brand, double price, char gender){
this.tag=tag;
this.brand=brand;
this.price=price;
this.gender=gender;
}
//Getters
public int getTag(){
return tag;
}
public double getPrice(){
return price;
}
public String getBrand(){
return brand;
}
public char getGender(){
return gender;
}
//Setters
public void setTage(int tag){
this.tag=tag;
}
public void setBrand(String brand){
this.brand=brand;
}
public void setPrice(double price){
this.price=price;
}
public void setGender(char gender){
this.gender=gender;
}
}