Results 1 to 3 of 3
  1. #1
    Chicken's Avatar WHY DAVE

    Join Date
    Jul 2012
    Country
    Posts
    174
    Thanked
    36
    Thanks
    45
    Write a class which instantiates a new array of type int called values with 5 numbers.

    2.Use a for loop to print out the values of the array all on one line separated by commas. When writing your for loop use the .length attribute to generalize the for loop for arrays of any size.

    Can anyone please give me the code to this? Thanks alot, gratz chicken <3

  2. #2
    Bunny's Avatar woof.

    Join Date
    Mar 2014
    Country
    Posts
    5,293
    Thanked
    2,873
    Thanks
    1,244
    i dont know Java but i heard its pretty similar to C# and i know that so heres my attempt

    class Program
    {
    public static void Main(string[] args)
    {
    int[] arr=new int[5];
    for(int i=0; i<arr.length; i++) //input loop
    {
    arr[i]=int.Parse(Console.ReadLine());
    }
    for(int i=0; i<arr.length; i++) //output loop
    {
    System.Console.Write(arr[i]);
    if(i=arr.length-1)
    break;
    System.Console.Write(", ");
    }
    }
    }
    Last edited by Bunny; 08-20-2018 at 09:09 PM.

  3. #3
    Chicken's Avatar WHY DAVE

    Join Date
    Jul 2012
    Country
    Posts
    174
    Thanked
    36
    Thanks
    45
    Originally Posted by Bunny View Post
    i dont know Java but i heard its pretty similar to C# and i know that so heres my attempt

    class Program
    {
    public static void Main(string[] args)
    {
    int[] arr=new int[5];
    for(int i=0; i<arr.length; i++) //input loop
    {
    arr[i]=int.Parse(Console.ReadLine());
    }
    for(int i=0; i<arr.length; i++) //output loop
    {
    System.Console.Write(arr[i]);
    if(i=arr.length-1)
    break;
    System.Console.Write(", ");
    }
    }
    }
    Thank u bunny for the help, really u dont know how that helps me lol im late asf in school. ty if anything ill just change some stuff from c# code to java

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)