thestudentnetwork

Thursday, 15 September 2016

Hackerrank solutions: Java Stdin and Stdout



Task: In this challenge, we must read 3 integers as inputs and then print them to stdout. Each integer should be printed on a new line.

Sample Input: 

43
54
123

Sample Output:

43
54
123

Quick Bits:

Stdin: Standard Input 
Stdout: Standard Output
Imports: java.util.*; (or)  java.util.Scanner;
Using Scanner: Scanner scan = new Scanner(System.in);

Solution:





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) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();            
String ans="";
if(n%2==1){
ans = "Weird";
}
else{
         

                if(n%2==0)
                {
                if(n>2 && n<5)
                    {
                    ans="Not Weird";
                }
                if(n>6 && n<=20)
                    {
                    ans= "Weird";
                }
                if(n>20)
                    {
                    ans="Not Weird";
                }
            }
              
                
            }
                
            
            System.out.println(ans);
            
        }
    }
Share:

0 comments:

Post a Comment

Definition List

Contact

Pages

Support