-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
45be0a6
commit 104711a
Showing
44 changed files
with
480 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
/* | ||
* Enter your code here. Print output to STDOUT. Your class should be named | ||
* Solution. | ||
*/ | ||
System.out.println("Hello, World."); | ||
System.out.println("Hello, Java."); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import java.util.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
Scanner scan = new Scanner(System.in); | ||
int a = scan.nextInt(); | ||
int b = scan.nextInt(); | ||
int c = scan.nextInt(); // Complete this line | ||
scan.close(); // Complete this line | ||
|
||
System.out.println(a); | ||
System.out.println(b); | ||
System.out.println(c); | ||
// Complete this line | ||
// Complete this line | ||
} | ||
} | ||
1 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import java.io.*; | ||
import java.math.*; | ||
import java.security.*; | ||
import java.text.*; | ||
import java.util.*; | ||
import java.util.concurrent.*; | ||
import java.util.regex.*; | ||
|
||
public class Solution { | ||
|
||
|
||
|
||
private static final Scanner scanner = new Scanner(System.in); | ||
|
||
public static void main(String[] args) { | ||
int N = scanner.nextInt(); | ||
scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); | ||
|
||
scanner.close(); | ||
|
||
|
||
if (N % 2 != 0) { | ||
System.out.println("Weird"); | ||
} | ||
else if (N <= 5 && N >= 2) { | ||
System.out.println("Not Weird"); | ||
} | ||
else if (N <= 20 && N >= 6) { | ||
System.out.println("Weird"); | ||
} | ||
else { | ||
System.out.println("Not Weird"); | ||
} | ||
} | ||
} | ||
1 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.Scanner; | ||
|
||
|
||
public class Solution { | ||
public static void main(String[] args) { | ||
|
||
|
||
Scanner input = new Scanner(System.in); | ||
int User = input.nextInt(); | ||
|
||
int i; | ||
int n = 10; | ||
|
||
for (i = 1 ; i <= n ; i++) { | ||
int result = User * i; | ||
System.out.println(User + " x " + i + " = " + result ); | ||
} | ||
} | ||
} | ||
1 |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
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 | ||
|
||
// Write your code here | ||
String s = Integer.toString(n); // Converting integer to string | ||
|
||
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); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import java.util.*; | ||
|
||
public class Solution { | ||
|
||
public static void main(String[] args) { | ||
|
||
Scanner scan = new Scanner(System.in); | ||
int n = scan.nextInt(); | ||
int[] a = new int[n]; | ||
|
||
// Read integers from input and store them in array a | ||
for (int i = 0; i < n; i++) { | ||
a[i] = scan.nextInt(); | ||
} | ||
scan.close(); | ||
|
||
// Prints each sequential element in array a | ||
for (int i = 0; i < a.length; i++) { | ||
System.out.println(a[i]); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import java.io.*; | ||
import java.util.*; | ||
import java.text.*; | ||
import java.math.*; | ||
import java.util.regex.*; | ||
|
||
class Animal { | ||
void walk() { | ||
System.out.println("I am walking"); | ||
} | ||
} | ||
|
||
class Bird extends Animal { | ||
void fly() { | ||
System.out.println("I am flying"); | ||
} | ||
|
||
void sing() { | ||
System.out.println("I am singing"); | ||
} | ||
} | ||
|
||
public class Solution { | ||
|
||
public static void main(String args[]) { | ||
|
||
Bird bird = new Bird(); | ||
bird.walk(); | ||
bird.fly(); | ||
bird.sing(); | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import java.util.*; | ||
|
||
abstract class Book { | ||
String title; | ||
|
||
abstract void setTitle(String s); | ||
|
||
String getTitle() { | ||
return title; | ||
} | ||
} | ||
|
||
// Write MyBook class here | ||
class MyBook extends Book { | ||
// Implementing the abstract method setTitle | ||
void setTitle(String s) { | ||
this.title = s; | ||
} | ||
} | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
// Book new_novel=new Book(); This line prHMain.java:25: error: Book is | ||
// abstract; cannot be instantiated | ||
Scanner sc = new Scanner(System.in); | ||
String title = sc.nextLine(); | ||
MyBook new_novel = new MyBook(); | ||
new_novel.setTitle(title); | ||
System.out.println("The title is: " + new_novel.getTitle()); | ||
sc.close(); | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import java.util.*; | ||
|
||
interface AdvancedArithmetic { | ||
int divisor_sum(int n); | ||
} | ||
|
||
// Write your code here | ||
class MyCalculator implements AdvancedArithmetic { | ||
public int divisor_sum(int n) { | ||
int sum = 0; | ||
// Loop through numbers from 1 to n and find divisors | ||
for (int i = 1; i <= n; i++) { | ||
if (n % i == 0) { | ||
sum += i; | ||
} | ||
} | ||
return sum; | ||
} | ||
} | ||
|
||
class Solution { | ||
public static void main(String[] args) { | ||
MyCalculator my_calculator = new MyCalculator(); | ||
System.out.print("I implemented: "); | ||
ImplementedInterfaceNames(my_calculator); | ||
Scanner sc = new Scanner(System.in); | ||
int n = sc.nextInt(); | ||
System.out.print(my_calculator.divisor_sum(n) + "\n"); | ||
sc.close(); | ||
} | ||
|
||
/* | ||
* ImplementedInterfaceNames method takes an object and prints the name of the | ||
* interfaces it implemented | ||
*/ | ||
static void ImplementedInterfaceNames(Object o) { | ||
Class[] theInterfaces = o.getClass().getInterfaces(); | ||
for (int i = 0; i < theInterfaces.length; i++) { | ||
String interfaceName = theInterfaces[i].getName(); | ||
System.out.println(interfaceName); | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
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) { | ||
/* | ||
* Enter your code here. Read input from STDIN. Print output to STDOUT. Your | ||
* class should be named Solution. | ||
*/ | ||
|
||
Scanner scanner = new Scanner(System.in); | ||
|
||
// First line input the length of List | ||
int N = scanner.nextInt(); | ||
|
||
List<Integer> L = new ArrayList<Integer>(N); | ||
|
||
for (int i = 0; i < N; i++) { | ||
L.add(scanner.nextInt()); | ||
} | ||
|
||
int Q = scanner.nextInt(); | ||
// System.out.println("Queries: " + Integer.toString(Q)); | ||
|
||
for (int i = 0; i < Q; i++) { | ||
String operation = scanner.next(); | ||
// System.out.println("Current operation is: " + operation); | ||
|
||
if (operation.equals("Insert")) { | ||
int index = scanner.nextInt(); | ||
int value = scanner.nextInt(); | ||
// System.out.println("Inserting element: " + Integer.toString(value) + " into | ||
// index: " + Integer.toString(index)); | ||
L.add(index, value); | ||
} | ||
|
||
else if (operation.equals("Delete")) { | ||
int index = scanner.nextInt(); | ||
// System.out.println("Removing element at index: " + Integer.toString(index)); | ||
L.remove(index); | ||
} | ||
} | ||
|
||
for (int element : L) | ||
|
||
{ | ||
System.out.print(element + " "); | ||
} | ||
|
||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
//Complete this code or write your own from scratch | ||
import java.util.*; | ||
import java.io.*; | ||
|
||
class Solution { | ||
public static void main(String[] argh) { | ||
Scanner in = new Scanner(System.in); | ||
|
||
int n = in.nextInt(); | ||
in.nextLine(); // this is to clear the buffer | ||
|
||
HashMap<String, Integer> phonebook = new HashMap<String, Integer>(n); | ||
|
||
// read in all the names and phones number | ||
for (int i = 0; i < n; i++) { | ||
String name = in.nextLine(); | ||
int phone = in.nextInt(); | ||
in.nextLine(); // this is to clear the buffer | ||
|
||
phonebook.put(name, phone); | ||
} | ||
|
||
// this section is where the queries of the names show up | ||
while (in.hasNext()) { // this is to check if there is a next line in the input stream | ||
String s = in.nextLine(); | ||
|
||
Integer phonenumber = phonebook.get(s); | ||
|
||
if (phonenumber == null) { | ||
System.out.println("Not found"); | ||
} | ||
|
||
else { | ||
System.out.println(s + "=" + Integer.toString(phonenumber)); | ||
} | ||
|
||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.