+ Reply to Thread
Results 1 to 2 of 2

Thread: read input and create an array for input

  1. #1

    read input and create an array for input

    I am creating a simple application that will read the input, and create an array of temperature values of type int. Then print out the values:
    Code:
    : java TempMedian 34 . . . + . + . +
    34 34 34 34 35 35 36 36 37
    : java TempMedian 7 - - - - . .
    7 6 5 4 3 3 3
    Code:
    '.' means no change '+' means an increase of 1 degree from the previous temperature '-' means a decrease of 1 degree from the previous temperature
    Could you please help me with that ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    30
    Here is the proper code :
    Code:
     public class Temp {
    public static void main(String[] args) {
    
        int t=0;
        if(args.length>1)
        {
            t=Integer.parseInt(args[0]);
            System.out.print(t+" ");
    
        }
    
    
        for(int i=0; i<args.length; i++)
        {
    
            if(args[i].equals("-"))
            {
                t--;
                System.out.print(t+" ");
            }
            else if(args[i].equals("+"))
            {
                t++;
                System.out.print(t+" ");
            }
            else if(args[i].equals("."))
            {
                System.out.print(t+" ");
            }
    
        }
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts