A Month of Coding Challenges with Java: Day 1 - Data Type
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 variables. */ int ii; double dd; String ss; /* 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. ii = Integer.parseInt(scan.nextLine()); dd = Double.parseDouble(scan.nextLine()); ss = scan.nextLine(); /* Print the sum of both integer variables on a new line. */ System.out.println(i+ii); /* Print the sum of the double variables on a new line. */ System.out.println(d+dd); /* Concatenate and print the String variables on a new line; the 's' variable above should be printed first. */ System.out.println(s+ss); scan.close(); } }
Run the listing program above and the result will be displayed like this :
Comments
Post a Comment