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.
Excuse me, im getting runtime error at testcase #1 here is a code and here is a question:
Objective
Today, we're discussing data types. Check out the Tutorial tab for learning materials and an instructional video!
Task
Complete the code in the editor below. The variables , , and are already declared and initialized for you. You must:
Declare variables: one of type int, one of type double, and one of type String.
Read lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables.
Use the operator to perform the following operations:
Print the sum of plus your int variable on a new line.
Print the sum of plus your double variable to a scale of one decimal place on a new line.
Concatenate with the string you read as input and print the result on a new line.
Note: If you are using a language that doesn't support using for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.
Input Format
The first line contains an integer that you must sum with .
The second line contains a double that you must sum with .
The third line contains a string that you must concatenate with .
Output Format
Print the sum of both integers on the first line, the sum of both doubles (scaled to decimal place) on the second line, and then the two concatenated strings on the third line.
Sample Input
12
4.0
is the best place to learn and practice coding!
Sample Output
16
8.0
HackerRank is the best place to learn and practice coding!
Explanation
When we sum the integers and , we get the integer .
When we sum the floating-point numbers and , we get .
When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.
You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above and reading input from stdin.
/* Declare second integer, double, and String variables. */intinputInt=scan.nextInt();doubleinputDouble=scan.nextDouble();Strings1=scan.next();Strings2=scan.next();Strings3=scan.next();Strings4=scan.next();Strings5=scan.next();Strings6=scan.next();Strings7=scan.next();Strings8=scan.next();Strings9=scan.next();/*String fullString = s + inputString;*//* Read and save an integer, double, and String to your variables.*//* Print the sum of both integer variables on a new line. */System.out.println(i+inputInt);/* Print the sum of the double variables on a new line. */System.out.println(d+inputDouble);/* Concatenate and print the String variables on a new line; the 's' variable above should be printed first. */System.out.println(s+""+s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+s9);
You're attempting to read content that isn't there in the second test case. You can't read input like that. Please review the tutorial closely, especially the breakdown of the Scanner example.
Alright, i havent been watching your tutorial before you said to watch it, thank you for reply tho, im not trying to do demagoguery, but it's working with the button run, so i assume it means that everything is correct and i'm getting values for my variables out of object System.in and it's printing out how expected, even tho it looks very ugly because of tons of variables and i could do it with the cycle, but anyways i will watch your tutorial for sure, thank you!
Here is a different variant of how i see it suppose to work, but it's still showing runtime error when i'm trying to submit:
/* Declare second integer, double, and String variables. */inti1;doubled1;Strings1;Strings2;Strings3;Strings4;Strings5;Strings6;Strings7;Strings8;Strings9;Strings10;/* Read and save an integer, double, and String to your variables.*/i1=scan.nextInt();d1=scan.nextDouble();s1=scan.next();s2=scan.next();s3=scan.next();s4=scan.next();s5=scan.next();s6=scan.next();s7=scan.next();s8=scan.next();s9=scan.next();s10=s1+" "+s2+" "+s3+" "+s4+" "+s5+" "+s6+" "+s7+" "+s8+" "+s9;/* Print the sum of both integer variables on a new line. */System.out.println(i+i1);/* Print the sum of the double variables on a new line. */System.out.println(d+d1);/* Concatenate and print the String variables on a new line; the 's' variable above should be printed first. */System.out.println(s+s10);
Sorry for being annoying, there we go, i fixed it this way, now everything is working, but anyways, send me the code please on how it suppose to look with scan.hasNext(); and then scan.next(); without doing a do while, thank you!
/* Declare second integer, double, and String variables. */inti1;doubled1;Strings1;/* Read and save an integer, double, and String to your variables.*/i1=scan.nextInt();d1=scan.nextDouble();/* Print the sum of both integer variables on a new line. */System.out.println(i+i1);/* Print the sum of the double variables on a new line. */System.out.println(d+d1);/* Concatenate and print the String variables on a new line; the 's' variable above should be printed first. */System.out.print(s);while(scan.hasNext()==true){s1=scan.next();System.out.print(s1+" ");}
Day 1: Data Types
You are viewing a single comment's thread. Return to all comments →
Excuse me, im getting runtime error at testcase #1 here is a code and here is a question: Objective Today, we're discussing data types. Check out the Tutorial tab for learning materials and an instructional video!
Task Complete the code in the editor below. The variables , , and are already declared and initialized for you. You must:
Declare variables: one of type int, one of type double, and one of type String. Read lines of input from stdin (according to the sequence given in the Input Format section below) and initialize your variables. Use the operator to perform the following operations: Print the sum of plus your int variable on a new line. Print the sum of plus your double variable to a scale of one decimal place on a new line. Concatenate with the string you read as input and print the result on a new line. Note: If you are using a language that doesn't support using for string concatenation (e.g.: C), you can just print one variable immediately following the other on the same line. The string provided in your editor must be printed first, immediately followed by the string you read as input.
Input Format
The first line contains an integer that you must sum with . The second line contains a double that you must sum with . The third line contains a string that you must concatenate with .
Output Format
Print the sum of both integers on the first line, the sum of both doubles (scaled to decimal place) on the second line, and then the two concatenated strings on the third line.
Sample Input
12 4.0 is the best place to learn and practice coding! Sample Output
16 8.0 HackerRank is the best place to learn and practice coding! Explanation
When we sum the integers and , we get the integer . When we sum the floating-point numbers and , we get . When we concatenate HackerRank with is the best place to learn and practice coding!, we get HackerRank is the best place to learn and practice coding!.
You will not pass this challenge if you attempt to assign the Sample Case values to your variables instead of following the instructions above and reading input from stdin.
Althought tescase #0 is working without a problems, but testcase # 1 is showing a runtime error...
You're attempting to read content that isn't there in the second test case. You can't read input like that. Please review the tutorial closely, especially the breakdown of the Scanner example.
Alright, i havent been watching your tutorial before you said to watch it, thank you for reply tho, im not trying to do demagoguery, but it's working with the button run, so i assume it means that everything is correct and i'm getting values for my variables out of object System.in and it's printing out how expected, even tho it looks very ugly because of tons of variables and i could do it with the cycle, but anyways i will watch your tutorial for sure, thank you!
Here is a different variant of how i see it suppose to work, but it's still showing runtime error when i'm trying to submit:
Sorry for being annoying, there we go, i fixed it this way, now everything is working, but anyways, send me the code please on how it suppose to look with scan.hasNext(); and then scan.next(); without doing a do while, thank you!
test case failed while submitting the code
in php pls