Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Really really need some help!!

Can some one please assist me with getting this program started:

Write a program called Largest.java that asks the user for how many numbers that they have. Then use a for loop that loops that number of times. In the loop, ask the user for a number. Keep track of what the largest number entered is. Print that out after the loop is over.

Comments

  • krishbalodakrishbaloda Member Posts: 45
    import java.io.*;

    class Largest {
    public static void main(String[] args)
    throws java.io.IOException {
    int n1=0,n2=0,temp=0;
    Scanner kbd = new Scanner(System.in);

    System.out.println("Enter Your First Number:");
    n1 = kbd.nextInt();

    for(int i=0; itemp)
    temp=n2;
    }
    System.out.println("largest = " + temp);
    }
    }

    hope this will work for u.

  • mlivingston64mlivingston64 Member Posts: 2
    Thanks so much. Perhaps you could explain the 'kbd' portion, why didnt you call it Scanner 'scan'? What does the 'throws java.io.IOException{ ' mean?

    If you get time, it would help me learn.

    Thank you
  • krishbalodakrishbaloda Member Posts: 45
    'kbd' is just an object of Scanner. u can name it whatever u like.

    'throws java.io.IOException' is a technique for exception handling. u r getting input from keyboard if any case ur program is not getting that input then it will throw the IO Exception.

    Good luck!!




  • krishbalodakrishbaloda Member Posts: 45
    keep posting!!!



  • anand003nanand003n Member Posts: 4
    [b][/b][size=5]Gud... is scanner a predefined object.. we normally use Bufferedreader or InputStream to get an inputstream. This seems to be new.It would be grt,if Could you pls explain on this (Scanner).[/size][/size]
  • anand003nanand003n Member Posts: 4
    This post has been deleted.
Sign In or Register to comment.