Posts

Showing posts with the label hackerrank

Conditional Statement Introduction

Image
Conditional is an essential part in programming. You can do many things with it. In the past, I read a book about basic programming. The author said that most of programs written from various language are only contain  repetition and conditional. So this time I’ll give a solution from 30 days challenge code from hackerrank . This is really a simple program about selection of odd and even number. Okay, the image above is the condition which we should implement in listing code. It’s quite easy right. First,  you input integer number (not decimal). Remember the constraint is number you input is from 1 to 100. .Then you start with selection whether the number is odd or not. In mathematic we all know that odd number is an integer number that can not be divided by 2. So if we operate it with modulo operation, odd number will result 1. Odd number should print “Weird”. Back again, if the number is not odd then do a selection again for even number. The range already men...

Simple Cashier Program Source Code in Java

Image
Now we are already in Day 2 in 30 day code challenge from hackerrank . This task will test you some uses of operators. As you know mathematic operations have to use several operator like “+” for sum, “-” for subtraction, “*” for multiplication, “/” for division, “%” for modulo operation, “( )” for do an operation which inside of it first, and so on. In here, you will make a program like a cashier. Given a meal cost, tip percentage, and  tax percentage will be resulted a total amount of money customer must be paid. Image below show you how the program should be. After understanding the algorithm of program, then here the solution : import java.util.*; import java.math.*; public class Arithmetic { public static void main(String[] args) { Scanner scan = new Scanner(System.in); double mealCost = scan.nextDouble(); // original meal price int tipPercent = scan.nextInt(); // tip percentage int taxPercent = scan.nextInt(); // tax pe...

A Month of Coding Challenges with Java: Day 1 - Data Type

Image
After we step  from hello word, then we will forward with Day 1. This challenge will remind you the use of data type in programming language. Since I will java then data type in here will follow java programming rule. But at least, most of programming language have the similarity in data type. The purpose of this task is to make operation from variable which have same data type.. First variable s,i and d are already declared and initialized. Your job is to declare new variable which have similar data type. Then use + operator for each corresponded data type variables. Here listing program for this task. 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 variabl...

A Month of Coding Challenges with Java: Day 0 - Hello World

Image
Hello world ! as I said in previous post, for the future post I will try to make solutions from challenges website. As for beginning to advanced we will start from 30 Days of Code Challenges . If you already registered in HackerRank you will asked if you want enroll this challenge. Well the purpose is to give you basic foundation. If you already finished one challenge you must wait for 24 hour to unlock the next challenge. If you tired of waiting you can enroll another challenge. There are so many of them, so you can choose as you like. So lets begin. We will start from Day 0 : Hello World. Most of programming tutorial will start to run hello world program. The purpose is to make sure that component of the said programming language is already installed properly in your PC. Besides that it gives you a nice introduction to that language. Imagine a toddler starts to learn speak from difficult word, I wonder how the outcome :D. So in the picture above the “Try Again” button used ...

5 Website for Coding Challenge

Image
Hello world ! This time I want to tell you something about future post. You may to comment it as you wish and I’d appreciate it so much :). You know we as programmer some time need to improve our skill to write a code and  make better algorithm for better program performance. There are various ways to improve it. You can take many projects to enhance your skill. However sometime projects do not come continuously to us. So one of that many ways is doing challenges given by someone else. In this broad sea of internet, there are many sites which provide challenges to fellow programming. They even given challenges in different level too. So for you who just step in this realm you can take beginner level. So, I will give some examples of that challenge site, here we go. HackerRank From the site, they explained it’s existency that HackerRank is a place where developers from everywhere throughout the world meet up to take care of issues in an extensive variety of Computer...