1]] program 1
import [Link];
public class Main
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
[Link]("Enter the 3 subjacts score out of 100");
float s1= [Link]();
float s2= [Link]();
float s3= [Link]();
float cgpa= ((s1+s2+s3)/30);
[Link]("Print the cgpa of student:");
[Link](cgpa);
2]]2nd program
import [Link];
public class Main
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
[Link]("Enter your name");
String name= [Link]();
[Link](" hello " +name+ " have a good day ");
} output:suma
Hello suma, have a good day
3]]3rd program
import [Link];
public class Main
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
[Link]("Enter kilometres");
float kilo= [Link]();
Float metre= ((kilo)*(1000));
[Link](metre);
3]]]] verify it pis int or not
import [Link];
public class Main
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
[Link]("Enter kilometres");
[Link]([Link]());
4]]] garde +8 encrpt and while decrptying same grade only.
public class Main
public static void main(String[] args) {
char grade ='A';
grade = (char) (grade+8);
System .[Link](grade);
grade = (char) (grade-8);
System .[Link](grade);
}
}
////// public class Main
public static void main(String[] args) {
char grade ='A';
char enc = (char) (grade+8);
System .[Link](enc);
char decrypt = (char) (enc-8);
System .[Link](decrypt);
5]]]]]
import [Link];
public class Main
public static void main(String[] args) {
Scanner s= new Scanner([Link]);
int grade =67;
int a=[Link]();
System .[Link](grade>a);
6]]]]
public class Main
public static void main(String[] args) {
int u=1;
int v=2;
int s=2;
int a=3;
float r=(v*v-u*u)/(2.0f*a*s);
System .[Link](r);
7]]]
import [Link];
public class Main
public static void main(String[] args) {
//String name=new String("harry");
//String name="harry";
//int age=21;
//[Link]("my name is:");
//[Link]("my name is %s and my age is %d",name,age);
Scanner sc= new Scanner([Link]);
String st=[Link]();
[Link](st);
8]]]] String operations
import [Link];
public class Main
public static void main(String[] args) {
//String name=new String("harry");
String name="HarRy";
int value=[Link]();
//[Link]("my name is:");
//[Link]("my name is %s and my age is %d",name,age);
//Scanner sc= new Scanner([Link]);
//String st=[Link]();
//String value1= [Link]();
//[Link](value1);
//[Link]([Link]());
//[Link]([Link](1));
//[Link]([Link](1,3));
[Link]([Link]('r','p'));
[Link]([Link]("rR","pi"));
[Link]([Link]('a'));
[Link]([Link]("ar"));
[Link]([Link]('r',1));
9]]]String practice sets
import [Link];
public class Main
public static void main(String[] args) {
//String name ="HELLO GOUDA";
//[Link]([Link]());
//String name =" hello ";
//[Link]([Link](' ','_'));
//String letter="Dear adarsh,Trans a lot";
//[Link](letter);
//[Link]([Link]("adarsh","sumitra"));
String letter="Dear adarsh, Trans a lot";
[Link]([Link](" "));
[Link]([Link](" "));
//String letter= "Dear harry,your java course is nice \n thanks";
//[Link](letter);
10]] logical operators
public class Main
public static void main(String[] args) {
boolean a=true;
boolean b=false;
[Link](a||b);
[Link](a&&b);
[Link](!a);
11]]If Else Ladder statement
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter your age:");
int age=[Link]();
//Elseif ladderStackTraceElement
if(age>56){
[Link]("you are experienced");
else if(age<20)
[Link]("You are under aged");
else{
[Link]("you are eligible enough to work");
12]]]Switch ststement
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter your name");
String name=[Link]();
switch(name){
case "suma":
[Link]("My name is suma");
break;
case "harry":
[Link]("My name is harry");
break;
default:
[Link]("My name is something which is none of your business");
[Link]("I hope you already know my name");
13]]] Practice programs set
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
int m1=[Link]();
int m2=[Link]();
int m3=[Link]();
float total= (m1+m2+m3)/3.0f;
[Link](total);
if(total>=30 && m1>=33 && m2>33&& m3>=33){
[Link]("you are promoted");
}else{
[Link]("you are not promoted");
///next program
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
float income=[Link]();
[Link]("The income of employee is %.2fL\n",income);
if(income>=2.5 && income<=5.0){
System .[Link]("Emploayee has to pay 5% of tax");
else{
System .[Link]("Emploayee has to pay more than 5% of tax");
///next program finding out whether its leap year or not
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter a year");
int year=[Link]();
if((year%400==0)|| (year%4==0 && year%100!=0)){
[Link]("Its a leap year");
}else{
[Link]("Its a not leap year");
//////findig tax of employee for a user input income in
Lakhs(Formula is tax=(income-baseprice)
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter a income in Lakhs:");
double income=[Link]();
double tax=0;
if(income<=2.5){
tax= 0;
}else if(income>2.5 && income<=5.0 ){
tax=0.05*(income-2.5);
}else if(income>5.0 && income<=10.0 ){
tax=0.05*(5.0-2.5)+0.2*(income-5.0);
}else if(income>10.0 ){
tax=0.05*(10.0-2.5)+0.2*(10.0-5.0)+0.3*(income-10.0);
[Link]("Final tax paid by employee is "+ tax +
" in Lakhs");
///////Enhanced Switch
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter the number of day to print:");
int day=[Link]();
switch(day){
case 1 ->[Link]("Monday");
case 2 ->[Link]("Tuesday");
case 3 ->[Link]("Wednesday");
case 4 ->[Link]("Thursday");
case 5 ->[Link]("Friday");
case 6 ->[Link]("Saturday");
case 7 ->[Link]("Sunday");
/////String operation endwith to find which website it is
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
[Link]("Enter the url to print:");
String url=[Link]();
if([Link](".Com")){
[Link]("This is commercial website");
}else if([Link](".Org")){
[Link]("This is organizational website");
}else if([Link](".in")){
[Link]("This is indian website");
}
///////Rock ,paper,Scissor program
import [Link];
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
Random ran= new Random();
[Link]("Enter the prerequites:");
[Link]("0: Rock");
[Link]("1: paper");
[Link]("2: Scissor");
[Link]("Enter my input::");
int myinput =[Link]();
[Link]("Enter computer input::");
int computer=[Link](3);
[Link](computer);
if(myinput==computer){
[Link]("Its draw");
}else if((myinput==0 && computer==2)||(myinput==1 && computer==0)||
(myinput==2 && computer==1)){
[Link]("I win");
else{
[Link]("computer win");
///////Rock ,paper ,scissor with 3 round of play and then
didcide who won
import [Link];
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
Random ran= new Random();
int myscore=0;
int computerscore=0;
for(int round=1;round<=3;round++){
[Link]("Enter the prerequites:");
[Link]("0: Rock");
[Link]("1: paper");
[Link]("2: Scissor");
[Link]("Enter my input::");
int myinput =[Link]();
[Link]("Enter computer input::");
int computer=[Link](3);
[Link](computer);
if(myinput==computer){
[Link]("Its draw");
computerscore=computerscore+1;
}else if((myinput==0 && computer==2)||(myinput==1 && computer==0)||
(myinput==2 && computer==1)){
[Link]("I win");
myscore=myscore+1;
else{
[Link]("computer win");
computerscore=computerscore+1;
[Link]("my score is "+myscore);
[Link]("computer score is "+computerscore);
if(myscore>computerscore){
[Link]("my score is high i won");
}else if(myscore<=computerscore){
[Link]("it is either draw or computer wins");
14]]varalaxmi even numbers
import [Link];
public class Main
public static void main(String[] args) {
Scanner start=new Scanner([Link]);
int count=0;
int a=[Link]();
int b=[Link]();
for(int i=a;i<b;i++)
if (i%2==0)
[Link](i);
count=count+1;
[Link]("total no of even no "+count);
15 ]]]First n odd niumbers
import [Link];
public class Main
public static void main(String[] args) {
Scanner start=new Scanner([Link]);
int count=0;
[Link] .println("how many first oddnumbers you want to print");
int n=[Link]();
[Link]("odd numbers are");
for(int i=0;i<n;i++)
{
[Link](2*i+1);
count=count+1;
[Link]("total no of odd no "+count);
16]] ]]]First n natural niumbers in reverse order (For loop)
import [Link];
public class Main
public static void main(String[] args) {
Scanner start=new Scanner([Link]);
int count=0;
[Link] .println("how many first numbers you want to print");
int n=[Link]();
[Link](" numbers are");
for(int i=n;i!=0;i--)
[Link](i);
count=count+1;
}
[Link]("total no "+count);
17]]]]Break statement
public class Main
public static void main(String[] args) {
int i=1;
while(i<7){
[Link](i);
i++;
//Break statement
if(i==3){
break;
//////Break for while loop
public class Main
{
public static void main(String[] args) {
int a=1;
do{
[Link](a);
if(a==2){
break;
a++;
}while(a<=5);
18]]]]contimue in all loops(while,for ,do while )
public class Main
public static void main(String[] args) {
int x = 1;
while (x <= 5) {
if (x == 3) {
x++;
continue;
[Link](x);
x++;
}
///////for loop continue statement
public class Main
public static void main(String[] args) {
for(int i=0;i<=5;i++){
if(i==2){
[Link]("Ending the loop");
continue;
[Link](i);
[Link]("Java is great");
///// Do while loop continue statement
public class Main
public static void main(String[] args) {
int i=0;
do{
i++;
if(i==2){
[Link]("This will skip the next lines");
continue;
[Link](i);
[Link]("java is great");
}while(i<5);
19]]]////pattern programs
public class Main
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++)
[Link]("* "); ///extra tab in this make output look like square
otherwise it look like rectangle
[Link]();
/////// hill climbing
public class Main
{
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++)///decreasing tab
[Link](" ");
for(int j=1;j<i;j++)////increasing *
[Link]("* ");
for(int j=1;j<=i;j++)////increasing *
[Link]("* ");
for(int j=i;j<=n;j++)
[Link](" ");
[Link]();
}
/////reverse hill pattern
public class Main
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++)////increasing tab
[Link](" ");
for(int j=i;j<n;j++)///decreasing star
[Link]("* ");
for(int j=i;j<=n;j++)///decreasing star
[Link]("* ");
[Link]();
20]]]] sum of first n even no using while loop
public class Main
{
public static void main(String[] args) {
int n=5;
for(int i=1;i<=n;i++){
for(int j=1;j<i;j++)////increasing tab
[Link](" ");
for(int j=i;j<n;j++)///decreasing star
[Link]("* ");
for(int j=i;j<=n;j++)///decreasing star
[Link]("* ");
[Link]();
21]]] multiplying table for given number
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
int i=[Link]();
int n= [Link]();
for(int j=1;j<=n;j++){
int multi=i*j;
[Link]("%d * %d = %d\n" ,i, j, multi);
22]]]multiplyig table of 10 in reverse order
import [Link];
public class Main {
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
int i=10;
int n = [Link]();
for(int j=n;j>=1;j--){
int multi=i*j;
[Link]("%d * %d = %d\n" ,i, j, multi);
23]] Array traversal using for each loop
public class Main
public static void main(String[] args) {
int [] marks={10,20,30};
for(int element: marks){
[Link](element);
24]]2D array priniting using user input value
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
int [ ][ ] marks;
marks = new int [2][3];
for( int i=0;i<[Link];i++){
for(int j=0;j<marks[i].length;j++){ //for loop condition for j is very important
marks[i][j]=[Link]();
[Link](marks[i][j] + " ");
[Link]();
}
25]]] practice set problem 1 --sum of 5 float numbers using arrays
import [Link];
public class Main
public static void main(String[] args) {
Scanner sc= new Scanner([Link]);
float sum=0;
float [ ] marks;
marks = new float [5];
[Link]("Enter the numbers");
for( int i=0;i<[Link];i++){
//for loop condition for j is very important
marks[i]=[Link]();
sum =sum+marks[i];
[Link](sum);
26]]] problem 2(key present or not)
public class Main
public static void main(String[] args) {
float [ ] marks={1.1f,2.2f,1.1f,2.2f,3.3f};
float key=1.1f;
boolean isInArray=false;
[Link]("check for key");
for( float element:marks){
if(key==element){
isInArray=true;
break;
}}
if(isInArray){
[Link]("present");
else{
[Link]("not present");
27]]]]problem 3
import [Link];
public class Main
public static void main(String[] args) {
int mat1={ {1,2,3}
{1,2,3} };
int mat2={ {2,1,3}
{3,2,1} };
int res={ {0,0,0} {0,0,0} };
for(int i=0;i<[Link]){
for(int j=0;j<mat2[i];j++){
res=mat1[i][j]+mat2[i][j];
[Link]();
[Link](res+" ");
Methods in jaava
28]] simple method or function used program
public class Main
{ static int logic(int x, int y){
int sum=x+y;
return sum;
}
public static void main(String[] args) {
[Link]("Hello World");
int a=2;
int b=3;
int last=logic(a,b);
[Link](last);