Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

public class Main

{
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Ex1.Addition of two numbers (direct method)

public class abc


{
public static void main(String args[])
{
int a = 225, b = 115, sum;
sum = a + b;
System.out.println("The sum of numbers is: "+sum);
}
}
.Addition of two numbers by taking values from user using scanner class.

import java.util.Scanner;
public class abc{
public static void main(String[] args){
int a, b, sum;
Scanner s = new Scanner(System.in);
System.out.println("Enter the first number: ");
a = s.nextInt();
System.out.println("Enter the second number: ");
b = s.nextInt();
sum = a + b;
System.out.println("Sum of the two numbers is: ");
System.out.println(sum);
}
}

Ex4.Addition of two numbers by taking values from user using buffered reader class.

import java.io.*;

class Addition {

public static void main(String args[]) throws Exception {

int a, b, c;

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the two numbers to add:");

a = Integer.parseInt(br.readLine());

b = Integer.parseInt(br.readLine());

c = a + b;

System.out.println("\nSum of two numbers:" + c);

}
Ex4.Addition of two numbers by taking values from user using DataInputStream class.

import java.io.*;
class Main {
public static void main(String args[]) throws Exception {
int a, b, c;
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Enter the two numbers to add:");
a = Integer.parseInt(dis.readLine());
b = Integer.parseInt(dis.readLine());
c = a + b;
System.out.println("\nSum of two numbers:" + c);
}
}
Ex5.Using classes and methods

a) Write a JAVA program to display default value of all primitive data type of
JAVA.
b) Write a case study on public static void main(250 words).
c) Five Bikers Compete in a race such that they drive at a constant speed which
may or may
not be the same as the other. To qualify the race, the speed of a racer must be more
than the average speed of all 5 racers. Take as input the speed of each racer and
print back the speed of qualifying racers.
public class Main {

static boolean a;
static int b;
static long c;
static float d;
static char e;
static double f;

public static void main(String[] args) {

System.out.println("Default value of boolean Type = " + a);


System.out.println("Default value of int Type = " + b);
System.out.println("Default value of long Type = " + c);
System.out.println("Default value of float Type = " + d);
System.out.println("Default value of char Type = " + e);
System.out.println("Default value of double Type = " + f);
}
}

import java.io.*;
import java.util.*;
class Race
{
public static void main(String [] args)
{
int R[]=new int[20];
float avg;
int sum=0;
System.out.println("Enter Speed of 5 members");
Scanner sc=new Scanner(System.in);
for(int j=1;j<=5;j++)
{
R[j]=sc.nextInt();
sum+=R[j];
}
avg=sum/5;
for(int i=1;i<=5;i++)
{
if(avg<R[i])
{
System.out.println("QualifiedRaceris:"+i+"with value="+R[i]);
}
}
}
}

You might also like