├── D_datatypes.java ├── E_ end of file.java ├── F_for loop 2.java ├── F_for loop.java ├── H_HELLO.java ├── I_if else.java ├── O_output formatting.java ├── README.md ├── S_Stdin Stdout 2.java ├── S_Stdin Stdout.java ├── S_static initializer block.java └── literal.java /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JAVA-programs -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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_static initializer block.java: -------------------------------------------------------------------------------- 1 | //https://www.hackerrank.com/challenges/java-static-initializer-block/problem 2 | //author : @shreyamalogi 3 | 4 | import java.io.*; 5 | import java.util.*; 6 | import java.text.*; 7 | import java.math.*; 8 | import java.util.regex.*; 9 | 10 | public class Solution { 11 | private static int B; 12 | private static int H; 13 | private static boolean flag; 14 | 15 | static { 16 | Scanner scan = new Scanner(System.in); 17 | B = scan.nextInt(); 18 | H = scan.nextInt(); 19 | scan.close(); 20 | if (B <= 0 || H <= 0) { 21 | System.out.println("java.lang.Exception: Breadth and height must be positive"); 22 | flag = false; 23 | } else { 24 | flag = true; 25 | } 26 | } 27 | 28 | public static void main(String[] args) { 29 | if (flag) { 30 | int area = B * H; 31 | System.out.print(area); 32 | } 33 | } // end of main 34 | } // end of class 35 | -------------------------------------------------------------------------------- /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 | --------------------------------------------------------------------------------