0

Hey there!! Back with another question...this code's output says "no output"...

As I click on "Run" ... Instead of taking two array inputs...it says "no output"!!! 😅😅 Here's the code : https://code.sololearn.com/c40hvKzZkVJm/?ref=app

25th Aug 2020, 8:48 AM
I M J
I M J - avatar
16 Réponses
+ 1
MJ Tech // Created by MJ Tech import java.util.*; class Merge { public static void main(String args[]) { int a[] = new int[5]; int b[] = new int[5]; // taking input fir two arrays Scanner sc = new Scanner (System.in); for (int i=1; i<a.length; i++) { a[i] = sc.nextInt(); } for(int i=1; i<b.length; i++) { b[i] = sc.nextInt(); } int c[]=new int[10]; for (int i=0; i<a.length; i++) c[i] = a[i]; for (int j=0; j<b.length;j++) c[j+a.length]=b[j]; System.out.println ("The merged array is "); for (int k=0; k<c.length;k++) { System.out.print(c[k]+","); } } } MJ Tech read this to understand what is public static void main in java. https://www.geeksforgeeks.org/understanding-public-static-void-mainstring-args-in-java/
25th Aug 2020, 9:05 AM
minirkk
minirkk - avatar
+ 2
rkk o... This happens to a beginner who has been treated with 'BlueJ' till now !!!😅
25th Aug 2020, 9:33 AM
I M J
I M J - avatar
+ 2
MJ Tech oh I got where you've went wrong. The way we input values here is SOLOLEARN is different. Input like this. 1 2 3 4 5 6 7 8 9 10
25th Aug 2020, 10:11 AM
minirkk
minirkk - avatar
+ 2
So in our case we have two arrays each of size 5. Now we input something like 1 2 3 4 5 6 7 8 9 10 the compiler knows that 10 values are inputted and I have two array each of size 5, so which mean I have to distribute the 10 values equally to the arrays (10/2 = 5) 5 values each.
25th Aug 2020, 10:15 AM
minirkk
minirkk - avatar
+ 2
MJ Tech see this code import java.util.*; public class Program { public static void main(String[] args) { /* 1 2 solo learn */ Scanner ob = new Scanner(System.in); int a = ob.nextInt(); int b = ob.nextInt(); String r = ob.next(); String s = ob.next(); System.out.println(a); System.out.println(b); System.out.println(r); System.out.println(s); } /* for something like this a = 1,2,3 ; b = 4,5,6 ; c = 7,8,9,10 input like: 1 2 3 4 5 6 7 8 9 10 } /* rkk So if there are 3 variables, a, b and c... and I want the values of them as: a = 1,2,3 ; b = 4,5,6 ; c = 7,8,9,10 ..then !! And if there are four variables, two integer type, and two string type...how to ensure exactly what gets what? Also how to take the input, in this case?? */
25th Aug 2020, 11:00 AM
minirkk
minirkk - avatar
+ 1
Again the same issue like in your previous question that is with this line public static void main(String args[]) Take my advise, revisit and revise your java course again.
25th Aug 2020, 8:50 AM
minirkk
minirkk - avatar
+ 1
MJ Tech you can do that by giving the values on commandline
25th Aug 2020, 8:59 AM
sarada lakshmi
sarada lakshmi - avatar
+ 1
MJ Tech Its the java programming language syntax and that's how the compiler understand something. Read this... https://www.geeksforgeeks.org/understanding-public-static-void-mainstring-args-in-java/ to clear your doubt.
25th Aug 2020, 9:30 AM
minirkk
minirkk - avatar
0
I think in main() argument should be public static void main(String args[] ). Are you trying to do it on command line?
25th Aug 2020, 8:52 AM
sarada lakshmi
sarada lakshmi - avatar
0
rkk hey!! Here I hav to take inputs...so why to write (String args [])
25th Aug 2020, 8:54 AM
I M J
I M J - avatar
0
rkk but sir please understand I want the program to take inputs ... not pre-destined values!!! So to take inputs we need to write public static void main (input)
25th Aug 2020, 8:58 AM
I M J
I M J - avatar
0
rkk what if I don't use the main method, use some other like 'accept' then ?
25th Aug 2020, 9:29 AM
I M J
I M J - avatar
0
rkk Can you tell how will I take inputs in your modified program? I entered " [1,2,3,4,5] and [6,7,8,9,10] in it and it showed ... Exception in thread "main".....
25th Aug 2020, 10:07 AM
I M J
I M J - avatar
0
Oh!! rkk But how will it understand which variable is taking what values !!
25th Aug 2020, 10:13 AM
I M J
I M J - avatar
0
rkk So if there are 3 variables, a, b and c... and I want the values of them as: a = 1,2,3 ; b = 4,5,6 ; c = 7,8,9,10 ..then !! And if there are four variables, two integer type, and two string type...how to ensure exactly what gets what? Also how to take the input, in this case??
25th Aug 2020, 10:26 AM
I M J
I M J - avatar
0
rkk ok thanks
25th Aug 2020, 1:13 PM
I M J
I M J - avatar