Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Account JAVA Cpa
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Account{ private int accountNumber; private String accountName; private String accountType; private double accountBalance; public Account(int no,String n,String tp,double bal) { accountNumber=no; accountName=n; accountType=tp; accountBalance=bal; } public String getAccountName() { return accountName; } public double getAccountBalance() { return accountBalance; } } class Rextester { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); Account[] ac=new Account[4]; for(int i=0;i<4;i++) { int num=sc.nextInt(); sc.nextLine(); String name=sc.nextLine(); String type=sc.nextLine(); double balance=sc.nextDouble(); sc.nextLine(); ac[i]=new Account(num,name,type,balance); } String newname=sc.nextLine(); double newbalance=sc.nextDouble(); int ans1=countAccountsByName(newname,ac); if(ans1==0) System.out.println("No Account found with given account name"); else System.out.println(ans1); Account[] ans2=searchAccountsByBalance(newbalance,ac); if(ans2==null) System.out.println("No such Account exists"); else{ for(int i=0;i<ans2.length;i++) { System.out.println(ans2[i].getAccountName()); } } } public static int countAccountsByName(String name,Account a[]) { int ans=0; for(int i=0;i<4;i++) { if((a[i].getAccountName()).equals(name)) ans++; } return ans; } public static Account [] searchAccountsByBalance(double amt,Account a[]) { int size=0; for(int i=0;i<4;i++) { if((a[i].getAccountBalance())>=amt) size++; } if(size==0) return null; Account arr[]=new Account[size]; int k=0; for(int i=0;i<4;i++) { if((a[i].getAccountBalance())>=amt) { arr[k++]=arr[i]; } } Account t=null; for(int i=0;i<size;i++) { for(int j=i;j<size;j++) { if((arr[i].getAccountBalance())>(arr[j].getAccountBalance())) { t=arr[i]; arr[i]=arr[j]; arr[j]=t; } } } return arr; } } /* link=>https://codebashers10.blogspot.com/2021/04/TCS-Xplore-CPA-10-April-2021-Shift-1-and-2-Java-Coding-Solution.html Input 107 Ashutosh Loan Account 21300.4 101 Rahul Demat Account 7000.0 102 Rahul Savings Account 3000.5 104 Sachin Retirement Account 10000.01 Rahul 10000 */
107 Ashutosh Loan Account 21300.4 101 Rahul Demat Account 7000.0 102 Rahul Savings Account 3000.5 104 Sachin Retirement Account 10000.01 Rahul 10000
[
-
]
Show input
Compilation time: 0.92 sec, absolute running time: 1.01 sec, cpu time: 0.59 sec, memory peak: 39 Mb, absolute service time: 2,04 sec
edit mode
|
history
|
discussion