├── README.md ├── H_HELLO.java ├── E_ end of file.java ├── literal.java ├── S_Stdin Stdout.java ├── S_Stdin Stdout 2.java ├── O_output formatting.java ├── F_for loop.java ├── F_for loop 2.java ├── S_static initializer block.java ├── I_if else.java └── D_datatypes.java /README.md: -------------------------------------------------------------------------------- 1 | # JAVA-programs -------------------------------------------------------------------------------- /H_HELLO.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/welcome-to-java/problem 2 | //author : @shreyamalogi 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | System.out.println("Hello, World."); 8 | System.out.println("Hello, Java."); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /E_ end of file.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-end-of-file/problem 2 | //author : shreyamalogi 3 | 4 | import java.util.Scanner; 5 | 6 | public class Solution { 7 | public static void main(String[] args) { 8 | Scanner scan = new Scanner(System.in); 9 | int i = 1; 10 | while (scan.hasNextLine()) { 11 | System.out.println(i + " " + scan.nextLine()); 12 | i++; 13 | } 14 | scan.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /literal.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | 3 | public class literal { 4 | public static void main(String[] args) { 5 | byte age = 19; 6 | int age2 = 32; 7 | short age3 = 57; 8 | long ageDino = 372343739l; 9 | char ch = 'A'; 10 | float f1 = 5.6f; 11 | double d1 = 4.66d; 12 | boolean a = true; 13 | System.out.println(age); 14 | String str = "tina"; 15 | System.out.println(str); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /S_Stdin Stdout.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-stdin-and-stdout-1/problem 2 | //author : @shreyammalogi 3 | 4 | import java.util.*; 5 | 6 | public class Solution { 7 | 8 | public static void main(String[] args) { 9 | Scanner scan = new Scanner(System.in); 10 | int a = scan.nextInt(); 11 | int b = scan.nextInt(); 12 | int c = scan.nextInt(); 13 | 14 | System.out.println(a); 15 | System.out.println(b); 16 | System.out.println(c); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /S_Stdin Stdout 2.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-stdin-stdout/problem 2 | //author: shreyamalogi 3 | 4 | import java.util.Scanner; 5 | 6 | public class Solution { 7 | 8 | public static void main(String[] args) { 9 | Scanner scan = new Scanner(System.in); 10 | int i = scan.nextInt(); 11 | double d = scan.nextDouble(); 12 | String s=""; 13 | while(scan.hasNext()) 14 | { 15 | s=scan.nextLine(); 16 | } 17 | 18 | System.out.println("String: " + s); 19 | System.out.println("Double: " + d); 20 | System.out.println("Int: " + i); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /O_output formatting.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-output-formatting/problem 2 | //author : shreyamalogi 3 | 4 | import java.util.Scanner; 5 | 6 | public class Solution { 7 | 8 | public static void main(String[] args) { 9 | Scanner sc=new Scanner(System.in); 10 | 11 | System.out.println("================================"); 12 | for(int i=0;i<3;i++){ 13 | String s1=sc.next(); 14 | int x=sc.nextInt(); 15 | 16 | System.out.printf("%-15s", s1); 17 | System.out.printf("%03d%n", x ); 18 | } 19 | System.out.println("================================"); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /F_for loop.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-loops-i/problem 2 | //author: shreyamalogi 3 | 4 | import java.io.*; 5 | import java.math.*; 6 | import java.security.*; 7 | import java.text.*; 8 | import java.util.*; 9 | import java.util.concurrent.*; 10 | import java.util.regex.*; 11 | 12 | public class Solution { 13 | private static final Scanner scanner = new Scanner(System.in); 14 | public static void main(String[] args) { 15 | int N = scanner.nextInt(); 16 | scanner.skip("(\r\n|[\n\r\u2028\u2029\u0085])?"); 17 | 18 | int i; 19 | for(i=1;i<=10;i++) 20 | { 21 | System.out.println(+N +" x " +i +" = " +N*i); 22 | } 23 | scanner.close(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /F_for loop 2.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-loops/problem 2 | //author: shreyamalogi 3 | 4 | import java.util.*; 5 | import java.io.*; 6 | 7 | class Solution 8 | { 9 | public static void main(String []argh) 10 | { 11 | Scanner in = new Scanner(System.in); 12 | int t=in.nextInt(); 13 | for(int i=0;i=2&&N<=5) 25 | { 26 | System.out.println("Not Weird"); 27 | } 28 | else if(N>=6 && N <= 20) 29 | { 30 | System.out.println("Weird"); 31 | } 32 | else if(N>=20) 33 | { 34 | System.out.println("Not Weird"); 35 | } 36 | scanner.close(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /D_datatypes.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-datatypes/problem 2 | //author: @shreyamalogi 3 | 4 | mport java.util.Scanner; 5 | 6 | class Solution { 7 | public static void main(String[] args) { 8 | Scanner scan = new Scanner(System.in); 9 | int t = scan.nextInt(); 10 | for (int i = 0; i < t; i++) { 11 | try { 12 | long x = scan.nextLong(); 13 | System.out.println(x + " can be fitted in:"); 14 | if (x >= Byte.MIN_VALUE && x <= Byte.MAX_VALUE) { 15 | System.out.println("* byte"); 16 | } 17 | if (x >= Short.MIN_VALUE && x <= Short.MAX_VALUE) { 18 | System.out.println("* short"); 19 | } 20 | if (x >= Integer.MIN_VALUE && x <= Integer.MAX_VALUE) { 21 | System.out.println("* int"); 22 | } 23 | if (x >= Long.MIN_VALUE && x <= Long.MAX_VALUE) { 24 | System.out.println("* long"); 25 | } 26 | } catch (Exception e) { 27 | System.out.println(scan.next() + " can't be fitted anywhere."); 28 | } 29 | } 30 | scan.close(); 31 | } 32 | } 33 | --------------------------------------------------------------------------------