Ek Code Chef challenge- Welcome Developers, Hackers & Noobs

Anjulayr

Well-known member
  • Sep 28, 2011
    1,711
    240
    83
    kotte
    Code:
    import java.util.Arrays;
    import java.util.Scanner;
    
    
    public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            int num = scan.nextInt();
            int[] arr = new int[num];
            for(int i =0;i<num;i++){
                arr[i] = scan.nextInt();
            }
            System.out.println("");
            Arrays.sort(arr);
            for(int j:arr){
                System.out.println(j);
            }
        }

    :D
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,851
    1
    9,597
    113
    Gampaha
    PHP:
    import java.util.Arrays;
    
    class numbers{
    
        private final static int lines = 8;
        private final static int numbers[] = new int[]{5,3,6,7,5,3,1,5};
    
    
        public static void main(String[] args) {
    
                int[] arr = new int[lines];
    
                for(int i =0;i<lines;i++){
                    arr[i] = numbers[i];
                }
    
                Arrays.sort(arr);
    
                for(int number:arr){
                    System.out.println(number);
                }
            }
    }

    :P:cool:
     

    Nerdy

    Member
    Oct 14, 2014
    28
    4
    0
    PHP:
    import java.util.Arrays;
    
    class numbers{
    
        private final static int lines = 8;
        private final static int numbers[] = new int[]{5,3,6,7,5,3,1,5};
    
    
        public static void main(String[] args) {
    
                int[] arr = new int[lines];
    
                for(int i =0;i<lines;i++){
                    arr[i] = numbers[i];
                }
    
                Arrays.sort(arr);
    
                for(int number:arr){
                    System.out.println(number);
                }
            }
    }

    :P:cool:
    you hard coded the numbers friend , its supposed to read from the user input
     

    MihiCherub

    Well-known member
  • Sep 14, 2009
    18,851
    1
    9,597
    113
    Gampaha
    you hard coded the numbers friend , its supposed to read from the user input
    Yes it is. That's how it demonstrates the user inputs. :yes: You don't have to use the Scanner class. All you have to do is grab the data and do the math. As long as you able to get the output exactly similar to the question you're done. ;)
     

    Sx3

    Well-known member
  • Apr 4, 2014
    3,394
    2,382
    113
    Here is a simple challenge

    Make a 1000 Line of 'A' without using for,while,do..while..goto..
    or the new line character(\n) and with the least amount of codes.

    USE ONLY JAVA :yes:
    example out put..

    A
    A
    A
    A
    A
    A
    .
    .
    .
     

    The_Killer

    Well-known member
  • Jan 20, 2014
    11,051
    2,196
    113
    WA, Straya 🇦🇺🦘
    www.elakiri.com
    I am little bit busy machan. What you're asking is bubble sort method. I don't have hands on experience with this so i don't like to be the wise guy by copy pasting a code from internet.

    Great work by posting this thread machan. This will help lots of people to face better in their technical interviews. Specially Virtusa, WSO2.

    Competitors, please try to avoid JDK or Language facilities to solve problems. Like arrays.sort(); Big companies expect you to learn those functions but they need to know that you know the theory behind it.


    thanks_for_sharing.png
     
    Last edited:

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    Make a 1000 Line of 'A' without using for,while,do..while..goto..
    or the new line character(\n) and with the least amount of codes.

    USE ONLY JAVA :yes:
    example out put..

    A
    A
    A
    A
    A
    A
    .
    .
    .
    Ungolfed:
    Code:
    /* package whatever; // don't place package name! */
     
    import java.util.*;
    import java.lang.*;
    import java.io.*;
     
    /* Name of the class has to be "Main" only if the class is public. */
    class Ideone
    {
        public static void main (String[] args) throws java.lang.Exception
        {
            System.out.println(new String(new char[1000]).replace("\0", "A\n"));  
        }
    }
    Golfed (205 bytes):
    Code:
    import java.util.*;import java.lang.*;import java.io.*;class Ideone{public static void main (String[] args) throws java.lang.Exception{System.out.println(new String(new char[1000]).replace("\0", "A\n"));}}
    Online:
    http://ideone.com/fork/iRJhpL
     
    Last edited:

    Tulip_Doll

    Member
    Feb 6, 2015
    208
    13
    0
    Florida
    Code:
    public class Sort {
    
    	public static void main(String[] args) {
    
    		int[] arr = {5, 3, 6, 7, 5, 1, 3, 5 };
    
    		sortArray(arr);
    		printArray(arr);
    
    	}
    
    	private static void sortArray(int[] arr) {
    		
    		for (int i = 0; i < arr.length; i++) {
    				
    			int low = i;
    			
    			for (int k = i + 1; k < arr.length; k++) {
    				
    					if (arr[k] < arr[low])
    
    					low = k;
    					
    				int temp = arr[i];
    				arr[i] = arr[low];
    				arr[low] = temp;
    	
    			}
    		}
    
    	}
    
    	private static void printArray(int[] arr) {
    
    		for (int i = 0; i < arr.length; i++)
    
    			System.out.println(arr[i]);
    
    	}
    
    }

    :)
     

    Ayeshlive

    Well-known member
  • Jul 1, 2011
    10,570
    943
    113
    *̶͑̾̾​̅ͫ͏̙̤g͛͆̾ͫ̑͆&
    here is my challenge.
    (I work for a company as a security audit, and this is a cryptography 101 algorithm. There are no "perfect" algorithms and such algorithms are not practical for today. But if you can write a good one, you are many steps ahead in your programming career! At least give it a try.


    You need to write an algorithm that accepts a 32 bit integer. Then, it has to provide two integers back, that when multiplied, produces the given number. Now the challenge is that BOTH of these returns values should be Prime numbers. If it can't find a prime number factorization, it should return 0.

    Example: input = 35; output should be "7 * 35".
    Input = 143; output should be 11*13 because 11*13 = 143.

    You can find examples off the internet. But try to write one first.

    Winner is chosen after a reasonable number of submissions. Fastest code wins.
    At the time of evaluation, a sample input will be given, and the snippet that takes the smallest amount of time yet provides the correct answer wins.
     
    Last edited: