// 1.
Program to show the use of print function
public class Message
{
public static void main( )
{
[Link]("Programming in Java");
[Link]("Grade: 8C");
[Link]("School: Trinity Central School");
}
}
//2. Program to find the sum of two numbers
import [Link].*;
public class AddTwo
{
public static void main( )
{
int one, two,sum;
Scanner ob = new Scanner([Link]);
[Link]("Enter the numbers: ");
one = [Link]( );
two = [Link]( );
sum = one + two;
[Link]("Sum: " + sum);
}
}
//3. Program to find the average of three numbers
import [Link].*;
public class AverageThree
{
public static void main( )
{
int n1, n2,n3,tot;
double avg;
Scanner ob = new Scanner([Link]);
[Link]("Enter three numbers: ");
n1 = [Link]( );
n2 = [Link]( );
n3 = [Link]( );
tot = n1 + n2 + n3;
avg = tot / 3;
[Link]("Total: " + tot);
[Link]("Average: " + avg);
}
}
//4. Program to find the circumference and area of a circle
import [Link].*;
public class AreaCir
{
public static void main( )
{
double area, cir, rad;
Scanner x = new Scanner([Link]);
[Link]("Enter the radius: ");
rad = [Link]( );
area = 3.142 * rad * rad;
cir = 2 * 3.142 * rad;
[Link]("Area of the circle: " + area);
[Link]("Circumference of the circle: " + cir);
}
}
// 5. Program to check for square or rectangle
import [Link].*;
public class CheckSq
{
public static void main( )
{
Scanner n = new Scanner([Link]);
double len, bd;
[Link]("Enter the sides: ");
len = [Link]( );
bd = [Link]( );
if(len == bd)
[Link]("It is a square");
else
[Link]("It is a rectangle");
}
}
// 6. Program to find the largest of three numbers
import [Link].*;
public class Largest
{
public static void main( )
{
int a, b, c, max;
Scanner x = new Scanner([Link]);
[Link]("Enter three numbers: ");
a = [Link]( );
b = [Link]( );
c = [Link]( );
if(a>b)
max = a;
else
max = b;
if(c>max)
max = c;
[Link]("Entered numbers are: " + a + " " + b + " " + c);
[Link]("Largest number is: " + max);
}
}
//7. Program to check for a buzz number
import [Link].*;
public class BuzzNum
{
public static void main( )
{
int num;
Scanner x = new Scanner([Link]);
[Link]("Enter a number: ");
num = [Link]( );
if(num%10 == 7 || num%7 == 0)
[Link](num + " is a buzz number");
else
[Link](num + " is NOT a buzz number");
}
}
//8. Program to input a number and check whether the number is even or odd.
import [Link].*;
public class Even
{
public static void main( )
{
Scanner n = new Scanner([Link]);
int num, x;
[Link]("Enter the number: ");
num = [Link]( );
x = num % 2;
if(x == 0)
[Link]("Number is even");
else
[Link]("Number is odd");
}
}
//9. Program check whether the number is positive or negative.
import [Link].*;
public class Positive
{
public static void main( )
{
Scanner n = new Scanner([Link]);
int num;
[Link]("Enter the number: ");
num = [Link]( );
if(num == 0)
[Link]("Entered number is zero");
else if(num > 0)
[Link]("Entered number is positive");
else
[Link]("Entered number is negative");
}
}
//10. Program to find the grade of the student
import [Link].*;
public class Grades
{
public static void main( )
{
Scanner in = new Scanner([Link]);
double marks;
char grade;
[Link]("Enter your marks: ");
marks = [Link]( );
if (marks < 101 && marks >=90)
grade = 'A';
else if(marks < 90 && marks >=70)
grade = 'B';
else if(marks < 70 && marks >=60)
grade = 'C';
else if(marks <60 && marks >=40)
grade = 'D';
else
grade = 'E';
[Link]("Grade: "+ grade);
}
}