0% found this document useful (0 votes)
29 views

Java Programs Intenship

Uploaded by

mrharshitha793
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Java Programs Intenship

Uploaded by

mrharshitha793
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

JAVA PROGRAMS INTENSHIP

1. Arithmetic operation

package javaproo;

public class arithmetic {


public static void main(String[] args)
{
System.out.println(10+5);
System.out.println(10-5);
System.out.println(10*5);
System.out.println(10/5);
System.out.println(10%5);
}
}

15
5
50
2
0

2. Check Grade example

package javaproo;

public class CheckgardeExample {


public static void main(String[] args) {
int marks=99;
if(marks < 50) {
System.out.println("Fail");
}
else if(marks>=50 && marks<60) {
System.out.println("D grade");
}
else if(marks>=60 && marks<70) {
System.out.println("C grade");
}
else if(marks>=70 && marks<80) {
System.out.println("B grade");
}
else if(marks>=80 && marks<90) {
System.out.println("A grade");
}
else if(marks>=90 && marks<100) {
System.out.println("A+ grade");
}
else {
System.out.println("Invalid");
}
}

A+ grade

3. To find length of word

package javaproo;

class hh {
public static void main(String[] args)
{
String m ="Jevi,Har,Ammu,Madhu";
int a = m.length();
System.out.println(m);
System.out.println(a);
}
}

Jevi,Har,Ammu,Madhu
19

4. If one

package javaproo;

public class ifone {


public static void main(String[] args) {
int x = 10;
int y = 12;
if(x + y > 20) {
System.out.println("X + y is grater than 20");
}
}
}

X + y is grater than 20

5.if two
package javaproo;

public class iftwo {


public static void main(String[] args) {
int x = 10;
int y = 12;
if(x + y < 20) {
System.out.println("X + y is grater than 10");
}
else
{
System.out.println("X + y is grater than 20");
}
}
}

X + y is grater than 20

5. If three

package javaproo;

public class ifthree {


public static void main(String[] args) {
String city = "Delhi";
if(city == "Meerut") {
System.out.println("City is meerut");
}else if(city == "Noida") {
System.out.println("City is Noida");
}else if(city == "Agra") {
System.out.println("City is Agra");
}else {
System.out.println(city);
}
}
}

Delhi

6.if four

public class iffour {


public static void main(String[] args) {
String address = "Delhi, India";
if(address.enith("India"))
{
if(address.contains("Meerut"))
{
System.out.println("Your city is Meerut");
}
else if(address.contains("Noida"))
{
System.out.println("Your city is Noida");
}
else
{
System.out.println(address.split(",")[1]);
}
}
else {
System.out.println("You are not living in
India");
}
}
}

6. Relational operaters

package javaproo;

public class relationaloperater {


public static void main (String[] args)
{
int a=10;
int b=7;
System.out.println(a==b);
System.out.println(a!=b);
System.out.println(a>b);
System.out.println(a<b);
System.out.println(a>=b);
System.out.println(a<=b);
}
}
false
true
true
false
true
false

7. Simple interest

package javaproo;
import java.util.Scanner;

public class SimpleIntrest {


public static void main (String[] args) {

Scanner in = new Scanner(System.in);


float p,t,r,sinterest;
System.out.println("Enter the principle:");
p = in.nextFloat();
System.out.println("Enter the time period :");
t = in.nextFloat();
System.out.println("Enter the rate of intrest:");
r = in.nextFloat();
sinterest=(p*t*r)/100;
System.out.println("Total Amount:"+sinterest);
}
}

Enter the principle:


3000
Enter the time period :
3
Enter the rate of intrest:
6
Total Amount:540.0

8. Sum

package javaproo;

class sum {
public static void main(String[] args)
{
int a=5;
int b=6;
int sum = a + b;
System.out.println("Sum of "+ a +" and "+ b +" is:
"+sum);
}
}

Sum of 5 and 6 is: 11

9. Star

package javaproo;
class summ {
public static void main(String[] args)
{
int i,j,k;
for(i=1;i<=5;i++)
System.out.print("* ");

for(i=1;i<=5;i++)
System.out.println("* ");

for(i=0;i<5;i++)
{
for(j=1;j<6;j++)
{
System.out.print("* ");
}
System.out.print("\n");
}

}
}

* * * * * *

*
*
*
*

* * * * *
* * * * *
* * * * *
* * * * *
* * * * *

10. Switch one

package javaproo;

public class switchone {


public static void main(String[] args) {
int num = 1;
switch(num) {
case 0: System.out.println("Number is 0");
break;
case 1: System.out.println("Number is 1");
break;
default:
System.out.println(num);
}
}
}

Number is 1

11. Switch two

package javaproo;

public class Switchtwo {


public static void main(String[] args) {
int month = 7;
String monthString="";
switch(month) {
case 1:monthString="1 -January"; break;
case 2:monthString="1 -February"; break;
case 3:monthString="1 -March"; break;
case 4:monthString="1 -April"; break;
case 5:monthString="1 -May"; break;
case 6:monthString="1 -June"; break;
case 7:monthString="1 -July"; break;
case 8:monthString="1 -August"; break;
case 9:monthString="1 -September"; break;
case 10:monthString="1 -October"; break;
case 11:monthString="1 -November"; break;
case 12:monthString="1 -December"; break;
default:System.out.println("Invalid Month!");
}
System.out.println(monthString);
}
}

1 -July

12. Switvhextwo
package javaproo;

public class Switvhextwo {


public static void main(String[] args) {
char branch = 'C';
int collegeYear = 4;
switch(collegeYear)
{
case 1: System.out.println("English, Maths,
Science");
break;
case 2:switch(branch)
{
case 'C':System.out.println("OS, Java, DS");
break;
}System.out.println("Micro processors, logic
switching theory");
break;
case 'E':System.out.println("Fundamentals of logic
design, Microelectonics");
break;
case 'M':System.out.println("Internal combustion
Engines, Mechanical Vibration");
break;
case 4:switch(branch)
{
case 'C':System.out.println("Data communication and
instruction modling");
break;
case 'M':System.out.println("Production Technology
Engineering");
break;
}
break;
}
}
}

Data communication and instruction modling

13. Ternaryoperater

package javaproo;

public class ternaryoperater {


public static void main (String[] args) {

int a=10;
int b=10;
System.out.println(a++ + ++a);
System.out.println(b++ + b++);

22
21
14.ternary
package javaproo;

public class ternaryopexample1 {


public static void main(String[] args) {
int a=2;
int b=5;
int min=(a<b)?a:b;
System.out.println(min);
}
}

15 . Unary

package javaproo;

public class unary {


public static void main (String[] args) {
int x=10;
System.out.println(x++);
System.out.println(++x);
System.out.println(x--);
System.out.println(--x);

}
}

10
12
12
10

16. for one

package javaproo;

public class forone {


public static void main(String[] xyz) {
int i =5;
for(i=0;i<=5;i++) {
System.out.println("Ohhhh");
}
}
}

Ohhhh
Ohhhh
Ohhhh
Ohhhh
Ohhhh
Ohhhh

17. for two

package javaproo;

public class fortwo {


public static void main(String[] xyz) {
String[] names =
{"java","c++","c","Python","javascript"};
System.out.println("Printing the content of arry
nsmes");
for(String name:names) {
System.out.println(name);
}
}
}

Printing the content of arry nsmes


java
c++
c
Python
javascript

18. for three

package javaproo;

public class forthree {


public static void main(String[] xyz) {
int i,j;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
System.out.println(i+" "+j);
}
}
}
}

1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

19. Pyramid example

package javaproo;

public class pyramidexample {


public static void main(String[] xyz) {
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
System.out.print("* ");
}
System.out.println();
}
}
}

*
* *
* * *
* * * *
* * * * *

20. ulta pyramid

package javaproo;

public class ulta {


public static void main(String[] xyz) {
int i,j,rows=5;
for(i=rows;i>=1;--i) //for(i=1;i<=term;i++)
{
for(j=1;j<=i;++j) //for(j=term;j>=i;j--)
{
System.out.print("* ");
}
System.out.println();
}
}
}

* * * * *
* * * *
* * *
* *
*

21. full pyramid

package javaproo;

public class fullpyramid {


public static void main(String[] xyz) {
int i,j;
for(i=0;i<=4;i++)
{
for(j=i;j<=4;j++){
System.out.print(" ");
}
for( j=1;j<=1 + (i*2);j++)
{
System.out.print(" * ");
}
System.out.println();
}
}
}

*
* * *
* * * * *
* * * * * * *
* * * * * * * * *

22. for triangle

package javaproo;

public class fortriangle {


public static void main(String[] xyz) {
int row, column, numberOfRows =5;
for(row=1;row<=numberOfRows; row++)
{
for(column=numberOfRows-row; column>=1; column-
-)
{
System.out.print(" ");
}
for(column=1; column<=row; column++)
{
System.out.print("* ");
}
System.out.println();
}
}
}

*
* *
* * *
* * * *
* * * * *

23. for array

package javaproo;

public class forArray{


public static void main(String[] xyz) {

int arr[] = {12,23,44,56,78};


for(int i:arr) {
System.out.println(i);
}
}
}

12
23
44
56
78

24. for count character

package javaproo;

public class forCountCharacter {


public static void main(String[] xyz) {
String string= "Welcome to MYSORE";
int count =0;

for(int i =0; i< string.length(); i++)


{
if(string.charAt(i) != ' ')
count++;
}
System.out.println("Total number of character in the
string is: "+count);
}
}
Total number of character in the string is: 15

25. Matrix mul

package javaproo;

public class MATRIXmul {


public static void main(String[] xyz) {

int a[][] = {{1,1,1},{2,2,2},{3,3,3}};


int b[][] = {{1,1,1},{2,2,2},{3,3,3}};

int c[][]= new int[3][3];

for(int i=0;i<3;i++) {
for(int j=0;j<3;j++) {
c[i][j]=0;
for(int k=0;k<3;k++) {
c[i][j] += a[i][j]*b[k][j];
}
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}

6 6 6
12 12 12
18 18 18

26. Mul matrix by user

package javaproo;

import java.util.Scanner;
public class mulmatuser {
public static void main(String[] xyz) {

int i,j,k;
Scanner in = new Scanner (System.in);
int a[][]= new int[2][2];
int b[][]= new int[2][2];

System.out.println("Enter matrix 1");


for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
a[i][j]=in.nextInt();
}
}
System.out.println("Enter matrix 2");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
b[i][j]=in.nextInt();
}
}
System.out.println("Matrix is:");
int c[][]= new int[2][2];
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
for(k=0;k<2;k++) {
c[i][j] += a[i][k]*b[k][j];
}
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}
}

Enter matrix 1
1 2
3 4
Enter matrix 2
1 2
3 4
Matrix is:
7 10
15 22

27. Do while one

package javaproo;

public class dowhileone {


public static void main(String[] xyz) {
int i =0;
System.out.println("printing the list of first 10
even numbers\n ");
do {
System.out.println(i);
i = i + 2;
}while(i<=10);
}
}

printing the list of first 10 even numbers

0
2
4
6
8
10

28. Break example one

package javaproo;

public class breakexone {

public static void main(String[] xyz) {


for(int i=0; i<=10; i++) {
System.out.println(i);
if(i==6) {
break;
}
}
}

0
1
2
3
4
5
6

29. Break example two

package javaproo;

public class breakexampletwo {


public static void main(String[] xyz) {
a:
for(int i=0; i<=10; i++) {
b:
for(int j=0; j<=15;j++) {
c:
for(int k=0; k<=20; k++) {
System.out.println(k);
if(k ==5) {
break a;
}
}
}
}
}
}

0
1
2
3
4
5

You might also like