programs of java
Information Technology students help m
2.1 Write a program to take n integers from command line and print their sum of product (product of first number and last number added to product of second number and second last number and so on).
2.2 Consider any two integers. Write a program to print sum of
their squares
2.3 write a program to print a roll no. Avagrage of two student
Answers
Answer:
Bird's-eye view. A Java program takes input values from the command line and prints a string of characters as output. By default, both command-line arguments and standard output are associated with an application that takes commands, which we refer to as the terminal window.
Command-line arguments. All of our classes have a main() method that takes a String array args[] as argument. That array is the sequence of command-line arguments that we type. If we intend for an argument to be a number, we must use a method such as Integer.parseInt() to convert it from String to the appropriate type.
Standard output. To print output values in our programs, we have been using System.out.println(). Java sends the results to an abstract stream of characters known as standard output. By default, the operating system connects standard output to the terminal window. All of the output in our programs so far has been appearing in the terminal window.
RandomSeq.java uses this model: It takes a command-line argument n and prints to standard output a sequence of n random numbers between 0 and 1.
To complete our programming model, we add the following libraries:
Standard input. Read numbers and strings from the user.
Standard drawing. Plot graphics.
Standard audio. Create sound.
Standard output. Java's System.out.print() and System.out.println() methods implement the basic standard output abstraction that we need. Nevertheless, to treat standard input and standard output in a uniform manner (and to provide a few technical improvements), we use similar methods that are defined in our StdOut library:
Standard output API
Java's print() and println() methods are the ones that you have been using. The printf() method gives us more control over the appearance of the output.
Formatted printing basics. In its simplest form, printf() takes two arguments. The first argument is called the format string. It contains a conversion specification that describes how the second argument is to be converted to a string for output.