• System.Out
• System.in
• Scanner Class
PROGRAM
Naming Conventions
• class name, interface name – First Letter of each word must be in upper case and rest in lower case. – e.g. String, StringBuffer, FileInputStream, ActionListener etc.
• method name, variable name – First word in lower case – For rest of words First Letter of each word must be in upper case and rest in lower case
– e.g. main(), print(), drawLine(), drawRoundRect() , toUpperCase( ) etc.
• package name – should be in lowercase letter
– e.g. java, lang, sql, util etc.
• constants name – should be in uppercase letter. – Words separated by underscore
– e.g. RED, YELLOW, MAX_PRIORITY etc.
Program Input
Input to our java program can be provided by using different ways.
– Console Input (using System.in)
– GUI Interface
– Command Line Arguments
– Input Dialog Box
• System.out Object
• This object is attached to our standard output device.
• This object is used to send data to standard output device.
• It provides us methods print(), println(), printf()..
etc to write data into the object .
• System.in Object
• This object is attached to our standard input device.
• This object is used to read data from standard input device.0
• It provides us method read() to read raw/binary data from the object
System.in
We have to wrap it in different objects to read its data such as
– Scanner
– BufferedReader
– etc
Class Scanner – java.util
Program's
- WAP to read radius of circle and find its area and circumference.
{
public static void main(String[] args)
{
Scanner likein=new Scanner(System.in);
System.out.print("Enter Radius ");
int r=likein.nextInt();
double a=3.14*r*r;
double c=2*3.14*r;
System.out.println("Area is "+a);
System.out.println("Circumference is "+c);
}
}- WAP to read length and
breadth of rectangle and find
its area and perimeter.
package com.company;
import java.util.Scanner;
public class Easy
{
public static void main(String[] args) {
Scanner likein = new Scanner(System.in);
System.out.print("Enter Length and Breadth:");
int l = likein.nextInt();
int b = likein.nextInt();
int a = l * b;
int p = 2 * (l + b);
System.out.println("Area is " + a);
System.out.println("Perimeter is " + p);
}
}
package com.company;
import java.util.Scanner;
public class Easy
{
public static void main(String[] args) {
Scanner likein = new Scanner(System.in);
System.out.print("Enter Length and Breadth:");
int l = likein.nextInt();
int b = likein.nextInt();
int a = l * b;
int p = 2 * (l + b);
System.out.println("Area is " + a);
System.out.println("Perimeter is " + p);
}
}

Nice 👍👏😊
ReplyDelete