We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 1: Data Types
  5. Discussions

Day 1: Data Types

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 3853 Discussions, By:

recency

Please Login in order to post a comment

  • jamiewmcandrew
    18 hours ago+ 0 comments

    Java Day 1 challenge:

    I succeeded but had some trouble with the string output, putting a blank '\n' in. Resovled this by using two nextLine()s with the second one reading into my string variable. Is there a better or suggested way or is one nextLine() to eat the '\n' left over from nextDouble() standard?

    0|
    Permalink
  • sjafars
    5 days ago+ 1 comment

    C# Day 2 Challenge

    Its my first time here. Can someone advise why the complie woriks but addional test case fails when i submit this C# Day 2 challenge? Link: [https://www.hackerrank.com/challenges/30-data-types/problem?isFullScreen=true]

    using System;
    using System.Collections.Generic;
    using System.IO;
    
    class Solution {
        static void Main(String[] args) {
            int i = 4;
            double d = 4.0;
            string s = "HackerRank ";
    
            
            // Declare second integer, double, and String variables.
            
            // Read and save an integer, double, and String to your variables.
            
            // Print the sum of both integer variables on a new line.
            
            // Print the sum of the double variables on a new line.
            
            // Concatenate and print the String variables on a new line
            // The 's' variable above should be printed first.
            int i2 = 12;
            double d2 = 4.0;
            string s2 = "is the best place to learn and practice coding!";
            Console.WriteLine(i+i2);
            Console.WriteLine   (String.Format("{0:0.0}",d+d2));
            Console.WriteLine(String.Concat(s + s2));
    
    
        }
    }
    
    0|
    Permalink
  • truongcuc05
    6 days ago+ 0 comments

    Here is my C assignment :

    #include <stdio.h>
    #include <string.h>
    #include <math.h>
    #include <stdlib.h>
    
    int main() {
        int i = 4;
        double d = 4.0;
        char s[] = "HackerRank ";
        int a;
        double b;
        char *c= (char*) malloc(1024*sizeof(char));
        scanf("%[^\n]%*c",c);
        a=atoi(c);
        scanf("%[^\n]%*c",c);
        b=atof(c);
        scanf("%[^\n]%*c",c);
        c= (char*) realloc(c, strlen(c)+1);
        printf("%d\n",i+a);
        printf("%-0.1f\n",d+b);
        printf("%s%s",s,c);
        return 0;
    }
    
    0|
    Permalink
  • dilencevi
    1 week ago+ 0 comments

    For C users. I had some head banging up the wall because of differencies how scanf worked in my WSL environment and a given here environment. Here is a program that worked in my WSL window: // Declare second integer, double, and String variables. int my_integer = 0; double my_duoble = 0.0; char *my_string; char final_string; my_string = (char)malloc(100 * sizeof(char)); final_string = (char*) malloc(200 * sizeof(char)); if(my_string == NULL || final_string == NULL) { printf("Memory allocation failed."); return 1; }

    // Read and save an integer, double, and String to your variables.
    scanf("%d", &my_integer);
    scanf("%lf", &my_duoble);   
    scanf("%[^\n]s", my_string);
    
    // Print the sum of both integer variables on a new line.
    printf("%d\n", i + my_integer);
    
    // Print the sum of the double variables on a new line.
    printf("%.1lf\n", d + my_duoble);
    
    // Concatenate and print the String variables on a new line
    // The 's' variable above should be printed first.
    strcpy(final_string, s);
    strcat(final_string, my_string);
    printf("%s\n", final_string);
    free(my_string);
    free(final_string);
    

    However, in the given environment nothing would be put into my_string. The remedy was to clean out a buffer from the previous input: <...>
    // Read and save an integer, double, and String to your variables. scanf("%d", &my_integer); scanf("%lf", &my_duoble);

    int leftover = 0;
    while ((leftover = getchar()) != '\n' && leftover != EOF);
    
    scanf("%[^\n]s", my_string);
    // Print the sum of both integer variables on a new line.
    printf("%d\n", i + my_integer);
    
        Then my program worked. But adding a buffer cleaning code in my program in WLS, caused it crash.
    

    Just wondering why that may be.... <...>

    Then my program worked. But adding a buffer cleaning code in my program in WLS, caused it crash. Just wondering why that may be....

    1|
    Permalink
  • thanosnuke
    2 weeks ago+ 0 comments

    For java: 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) {
        int i = 4;
        double d = 4.0;
        String s = "HackerRank ";
    
        Scanner scan = new Scanner(System.in);
    
        /* Declare second integer, double, and String variables. */
        int j = scan.nextInt();
        double e = scan.nextDouble();
        scan.nextLine();
        String k = scan.nextLine();
        String o = s+k;
    
        /* Read and save an integer, double, and String to your variables.*/
        // Note: If you have trouble reading the entire String, please go back and review the Tutorial closely.
    
        /* Print the sum of both integer variables on a new line. */
        System.out.println(i+j);
    
        /* Print the sum of the double variables on a new line. */
        System.out.println(d+e);
        /* Concatenate and print the String variables on a new line; 
            the 's' variable above should be printed first. */
        System.out.println(o);
        scan.close();
    }
    

    }

    0|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy