[JAVA][HackerRank] 30 Days of code Day 1


Day1-1. Hello World

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) {
        // Create a Scanner object to read input from stdin.
		Scanner scan = new Scanner(System.in); 
		
		// Read a full line of input from stdin and save it to our variable, inputString.
		String inputString = scan.nextLine(); 
		// Close the scanner object, because we've finished reading 
        // all of the input from stdin needed for this challenge.
		scan.close(); 
      
		// Print a string literal saying "Hello, World." to stdout.
		System.out.println("Hello, World.");
      
	    // TODO: Write a line of code here that prints the contents of inputString to stdout.
        
        System.out.println(inputString);
         
	}
}

Day1-2. Data types

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 i2 = scan.nextInt();
        double d2 = scan.nextDouble();
        String s2 =scan.next() + scan.nextLine();

        int sum = i + i2;
        double sumd = d + d2;
        String con = s.concat(s2);

        System.out.println(sum);
        System.out.printf("%.1f \n",sumd);
        System.out.println(con);
        /* 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 + secondInt);
        /* Print the sum of the double variables on a new line. */
		// System.out.println(d + secondDouble);
        /* Concatenate and print the String variables on a new line; 
        	the 's' variable above should be printed first. */
        // System.out.println(s + secondString);

        scan.close();





© 2018. by sora

Powered by sora