Added 15 solutions
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import java.util.Scanner;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* Read input */
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
double payment = scanner.nextDouble();
|
||||
scanner.close();
|
||||
|
||||
/* Create custom Locale for India.
|
||||
I used the "IANA Language Subtag Registry" to find India's country code */
|
||||
Locale indiaLocale = new Locale("en", "IN");
|
||||
|
||||
/* Create NumberFormats using Locales */
|
||||
NumberFormat us = NumberFormat.getCurrencyInstance(Locale.US);
|
||||
NumberFormat india = NumberFormat.getCurrencyInstance(indiaLocale);
|
||||
NumberFormat china = NumberFormat.getCurrencyInstance(Locale.CHINA);
|
||||
NumberFormat france = NumberFormat.getCurrencyInstance(Locale.FRANCE);
|
||||
|
||||
/* Print output */
|
||||
System.out.println("US: " + us.format(payment));
|
||||
System.out.println("India: " + india.format(payment));
|
||||
System.out.println("China: " + china.format(payment));
|
||||
System.out.println("France: " + france.format(payment));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Solution{
|
||||
public static void main(String []args) {
|
||||
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int t = scan.nextInt();
|
||||
|
||||
for (int i = 0; i < t; i++) {
|
||||
try {
|
||||
long x = scan.nextLong();
|
||||
System.out.println(x + " can be fitted in:");
|
||||
if (x >= Byte.MIN_VALUE && x <= Byte.MAX_VALUE) {
|
||||
System.out.println("* byte");
|
||||
}
|
||||
if (x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) {
|
||||
System.out.println("* short");
|
||||
}
|
||||
if (x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE) {
|
||||
System.out.println("* int");
|
||||
}
|
||||
if (x >= Long.MIN_VALUE && x <= Long.MAX_VALUE) {
|
||||
System.out.println("* long");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
System.out.println(scan.next() +" can't be fitted anywhere.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* Read input */
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int month = scan.nextInt();
|
||||
int day = scan.nextInt();
|
||||
int year = scan.nextInt();
|
||||
scan.close();
|
||||
|
||||
/* Create LocalDate instance */
|
||||
LocalDate date = LocalDate.of(year, month, day);
|
||||
System.out.println(date.getDayOfWeek());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int i = 1;
|
||||
while (scan.hasNextLine()) {
|
||||
System.out.println(i + " " + scan.nextLine());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import java.util.*;
|
||||
import java.security.*;
|
||||
public class Solution {
|
||||
public static void main(String[] args) {
|
||||
|
||||
DoNotTerminate.forbidExit();
|
||||
|
||||
try {
|
||||
Scanner in = new Scanner(System.in);
|
||||
int n = in .nextInt();
|
||||
in.close();
|
||||
//String s=???; Complete this line below
|
||||
|
||||
/* Here are 3 ways to convert an int to a String */
|
||||
// String s = String.valueOf(n);
|
||||
// String s = Integer.toString(n);
|
||||
String s = "" + n;
|
||||
|
||||
if (n == Integer.parseInt(s)) {
|
||||
System.out.println("Good job");
|
||||
} else {
|
||||
System.out.println("Wrong answer.");
|
||||
}
|
||||
} catch (DoNotTerminate.ExitTrappedException e) {
|
||||
System.out.println("Unsuccessful Termination!!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//The following class will prevent you from terminating the code using exit(0)!
|
||||
class DoNotTerminate {
|
||||
|
||||
public static class ExitTrappedException extends SecurityException {
|
||||
|
||||
private static final long serialVersionUID = 1;
|
||||
}
|
||||
|
||||
public static void forbidExit() {
|
||||
final SecurityManager securityManager = new SecurityManager() {
|
||||
@Override
|
||||
public void checkPermission(Permission permission) {
|
||||
if (permission.getName().contains("exitVM")) {
|
||||
throw new ExitTrappedException();
|
||||
}
|
||||
}
|
||||
};
|
||||
System.setSecurityManager(securityManager);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int multiplier = scan.nextInt();
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
System.out.format("%d x %d = %d%n", multiplier, i , i * multiplier);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
class Solution{
|
||||
public static void main(String []args) {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
int t = scan.nextInt();
|
||||
for (int i = 0; i < t; i++) {
|
||||
int a = scan.nextInt();
|
||||
int b = scan.nextInt();
|
||||
int n = scan.nextInt();
|
||||
|
||||
for (int j = 0; j < n; j++) {
|
||||
a += b * (int) Math.pow(2, j);
|
||||
System.out.print(a + " ");
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
scan.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Solution {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
System.out.println("================================");
|
||||
for (int i = 0; i < 3; i++) {
|
||||
String s1 = sc.next();
|
||||
int x = sc.nextInt();
|
||||
System.out.format("%-15s%03d%n", s1, x);
|
||||
}
|
||||
System.out.println("================================");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.text.*;
|
||||
import java.math.*;
|
||||
import java.util.regex.*;
|
||||
|
||||
public class Solution {
|
||||
private static int B;
|
||||
private static int H;
|
||||
private static boolean flag;
|
||||
|
||||
static {
|
||||
Scanner scan = new Scanner(System.in);
|
||||
B = scan.nextInt();
|
||||
H = scan.nextInt();
|
||||
scan.close();
|
||||
if (B <= 0 || H <= 0) {
|
||||
System.out.println("java.lang.Exception: Breadth and height must be positive");
|
||||
flag = false;
|
||||
} else {
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args){
|
||||
if(flag){
|
||||
int area=B*H;
|
||||
System.out.print(area);
|
||||
}
|
||||
|
||||
}//end of main
|
||||
|
||||
}//end of class
|
||||
Reference in New Issue
Block a user