import java.util.Scanner; public class String_Length { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str; int n; System.out.println("Enter a string"); str=sc.nextLine(); n=str.length(); System.out.println("The length of the string is "+n); }//end of main method }//end of class String_Length
// Enter a string "COMPUHELP" from the user and count the number of vowels in it. import java.util.Scanner; public class Count_Vowels { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str; int count=0; int n; System.out.println("Enter a string"); str=sc.nextLine(); n=str.length(); //counting the length of the string. for(int i=0;i<n;i++) { if(str.charAt(i)=='a'||str.charAt(i)=='e'||str.charAt(i)=='i'||str.charAt(i)=='o'||str.charAt(i)=='u') { count++; } } System.out.println("Number of vowels present in string are "+count); }//end of main method }//end of class Count_Vowels
/*Enter a string from the user in lower case and change all the vowels of the entered string in upper case.*/ import java.util.Scanner; public class V_UpperCase { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str,str1=""; int n,i; System.out.println("Enter a string in Lowercase"); str=sc.nextLine(); n=str.length(); for(i=0;i<n;i++) { if(str.charAt(i)=='a'||str.charAt(i)=='e'||str.charAt(i)=='i'||str.charAt(i)=='o'||str.charAt(i)=='u') { str1=str1+str.substring(i,i+1).toUpperCase(); }//end of if block else { str1=str1+str.substring(i,i+1); } //end of else block }//end of for loop System.out.println(str1); }//end of main method }//end of class V_UpperCase
//Enter a string from the user and count the number of words present in the entered string. import java.util.Scanner; public class Count_Words { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; int n, i,space=0; System.out.println("Enter a string"); str = sc.nextLine(); n = str.length(); for(i=0;i<n;i++) { if(str.charAt(i)==' ') { space++; } }// end of for loop System.out.println("The number of words present in the string are "+(space+1)); } //end of main method }//end of class Count_Words
//Enter a String from the user and print those characters that they have space before them. import java.util.Scanner; public class Space_Before_Character { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; int n, i; System.out.println("Enter a string"); str = sc.nextLine(); n = str.length(); for(i=0;i<n;i++) { if(str.charAt(i)==' ') { System.out.println(str.charAt(i+1)); } }//end of for loop }//end of main method }//end of class Space_Before_Character
/*Enter a string from the user and count how many times only two vowels occur together in the entered string.*/ import java.util.Scanner; public class Two_Vowels_Together { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; int n, i,count=0; System.out.println("Enter a string"); str = sc.nextLine(); n = str.length(); for(i=0;i<n-1;i++) { if(str.charAt(i)=='a'||str.charAt(i)=='e'||str.charAt(i)=='i'||str.charAt(i)=='o'||str.charAt(i)=='u') { if(str.charAt(i+1)=='a'||str.charAt(i+1)=='e'||str.charAt(i+1)=='i'||str.charAt(i+1)=='o'||str.charAt(i+1)=='u') { count++; } //end of inner if }//end of outer if }//enf of for loop System.out.println("The number of vowels together are "+count); }//end of main method }//end of class Two_Vowels_Together
//Enter a string from the user and print the first and last word of the entered string. import java.util.Scanner; public class First_Last_Word { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; int wl=0; System.out.println("Enter a string"); str = sc.nextLine(); String str1[]=str.split(" "); wl=str1.length; System.out.println(str1[0]); System.out.println(str1[wl-1]); }//end of main method }//end of class First_Last_Word
/*Enter a string from the user in uppercase and change each vowel present at the end of the words of the entered string in lowercase.*/ import java.util.Scanner; public class Vowel_End_UpperCase { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str,strcat=""; int n,wl; System.out.println("Enter a string in Uppercase"); str=sc.nextLine(); String str1[]=str.split(" "); wl=str1.length; for(int i=0;i<wl;i++) { n=str1[i].length(); if(str1[i].charAt(n-1)=='A'||str1[i].charAt(n-1)=='E'||str1[i].charAt(n-1)=='I'||str1[i].charAt(n-1)=='O'||str1[i].charAt(n-1)=='U') { strcat=strcat+str1[i].substring(0,n-1)+str1[i].substring(n-1).toLowerCase()+" "; } else { strcat=strcat+str1[i]+" "; } } System.out.println(strcat); }//end of main method }//end of class Vowel_End_UpperCase
/*Enter two strings from the user and check if both the strings are equal or not. If the two strings are equal then print "strings are equal" otherwise print "strings are not equal". */ import java.util.Scanner; public class Two_Strings_Equal { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str1,str2; System.out.println("Enter first string"); str1=sc.nextLine(); System.out.println("Enter second string"); str2=sc.nextLine(); if(str1.equalsIgnoreCase(str2)) { System.out.println("Strings are equal"); } else { System.out.println("Strings are not equal"); } }// end of main method }//end of class Two_Strings_Equal
//Enter a string from the user and concatenate the alternative words of the string together. import java.util.Scanner; public class Concat_Alternative_Words { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str; System.out.println("Enter a string"); str=sc.nextLine(); int n,wl; n=str.length(); String str1[]=str.split(" "); wl=str1.length; for(int i=0;i<wl;i++) { if(i%2==0) { System.out.print(str1[i]+" "); } } }//end of main method }//end of class Concat_Alternative_Words
import java.util.Scanner; //Enter a string from the user in lowercase and capitalize each word of the string. public class Capitalize_Each_Word { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str,strcat=""; System.out.println("Enter a string in lowercase"); str=sc.nextLine(); String str1[]=str.split(" "); int wl,n; wl=str1.length; for(int i=0;i<wl;i++) { n=str1[i].length(); strcat=strcat+str1[i].substring(0,1).toUpperCase()+str1[i].substring(1,n)+" "; } System.out.println(strcat); }//end of main method }//end of class Capitalize_Each_Word
//Enter a string "Compuhelp" from the user and print only "help" from the entered string. import java.util.Scanner; public class Print_Help { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str,strcat=""; System.out.println("Enter a string"); str=sc.nextLine(); int n=str.length(); System.out.println(str.substring(5,n)); }//end of main method }//end of class Print_Help
/*Enter a string from the user and find the first and last index number of the character entered by the user.*/ import java.util.Scanner; public class Index_First_Last { public static void main(String[] args) { Scanner sc=new Scanner(System.in); String str; char ch; System.out.println("Enter A string"); str=sc.nextLine(); System.out.println("Enter a character"); ch=sc.next().charAt(0); System.out.println("The first index number of the entered character is "+str.indexOf(ch)); System.out.println("The last index number of the entered character is "+str.lastIndexOf(ch)); }//end of main method }//end of class Index_First_Last
import java.util.Scanner; public class String_Replace { public static void main(String[] args) { String str1=new String(); String str2=new String(); Scanner sc=new Scanner(System.in); System.out.println("Enter a string "); str1=sc.nextLine(); str2=str1.replace("help","ter"); System.out.println(str2); }//end of main method }//end of class String_Replace
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int marks; System.out.println("Enter marks "); marks=scr.nextInt(); if(marks>=80 && marks<=100) { System.out.println("A Grade"); } else if(marks>=60 && marks<80) { System.out.println("B Grade"); } else if(marks>=40 && marks<60) { System.out.println("C Grade"); } else if(marks>=0 && marks<40) { System.out.println("Fail"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number "); num=scr.nextInt(); if(num>0) { System.out.println("Number is Positive"); } else if(num<0) { System.out.println("Number is Negative"); } //else if(num==0) else { System.out.println("Number is Zero"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number "); num=scr.nextInt(); if(num%2==0) { System.out.println("Number is even"); } else { System.out.println("Number is odd"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { char ch; Scanner scr=new Scanner(System.in); System.out.println("Enter any character "); ch=scr.next().charAt(0); if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U') { System.out.println("character is vowel"); } else { System.out.println("character is consonent"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { char ch; Scanner scr=new Scanner(System.in); System.out.println("Enter any character "); ch=scr.next().charAt(0); if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U') { System.out.println("character is vowel"); } else if(ch=='@'||ch=='!'||ch=='#'||ch=='%'||ch=='&'||ch=='*') { System.out.println("character is special"); } else { System.out.println("character is consonent"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number "); num=scr.nextInt(); if(num==1) { System.out.println("Day is Monday"); } else if(num==2) { System.out.println("Day is Tuesday"); } if(num==3) { System.out.println("Day is Wednesday"); } if(num==4) { System.out.println("Day is Thursday"); } if(num==5) { System.out.println("Day is Friday"); } if(num==6) { System.out.println("Day is Saturday"); } if(num==7) { System.out.println("Day is Sunday"); } }//end of main }//end of class urn 0; }
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number between 0 to 9"); num=scr.nextInt(); if(num==0) { System.out.println("You entered Zero"); } else if(num==1) { System.out.println("You entered One"); } else if(num==2) { System.out.println("You entered Two"); } else if(num==3) { System.out.println("You entered Three"); } else if(num==4) { System.out.println("You entered Four"); } else if(num==5) { System.out.println("You entered Five"); } else if(num==6) { System.out.println("You entered Six"); } else if(num==7) { System.out.println("You entered Seven"); } else if(num==8) { System.out.println("You entered Eight"); } else if(num==9) { System.out.println("You entered Nine"); } else { System.out.println("wrong input"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number between 1 and 12:"); num=scr.nextInt(); if(num==1) { System.out.println("You entered January"); } else if(num==2) { System.out.println("You entered Feburary"); } else if(num==3) { System.out.println("You entered March"); } else if(num==4) { System.out.println("You entered April"); } else if(num==5) { System.out.println("You entered May"); } else if(num==6) { System.out.println("You entered June"); } else if(num==7) { System.out.println("You entered July"); } else if(num==8) { System.out.println("You entered August"); } else if(num==9) { System.out.println("You entered September"); } else if(num==10) { System.out.println("You entered October"); } else if(num==11) { System.out.println("You entered November"); } else if(num==12) { System.out.println("You entered December"); } else { System.out.println("wrong input"); } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int choice,num1,num2,res; System.out.println("Press 1 for addition"); System.out.println("Press 2 for subtraction"); System.out.println("Press 3 for multiplication"); System.out.println("Press 4 for division"); System.out.println("Press 5 for exit"); choice=scr.nextInt(); if(choice<=4) { System.out.println("Enter first number:"); num1 = scr.nextInt(); System.out.println("Enter second number:"); num2 = scr.nextInt(); if (choice == 1) { res = num1 + num2; System.out.println("The sum is: " + res); } else if (choice == 2) { res = num1 - num2; System.out.println("The difference is: " + res); } else if (choice == 3) { res = num1 * num2; System.out.println("The multiplication is: " + res); } else if (choice == 4) { res = num1 / num2; System.out.println("The division is: " + res); } else if (choice == 5) { System.exit(0); } } }//end of main }//end of class
import java.util.Scanner; public class if_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int a, b ,c; System.out.println("Enter first number: "); a= scr.nextInt(); System.out.println("Enter second number: "); b= scr.nextInt(); System.out.println("Enter third number: "); c= scr.nextInt(); if(a>b && a>c) { System.out.println("First number is greater"); } else if(b>a && b>c) { System.out.println("Second number is greater"); } else { System.out.println("Third number is greater"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number between 0 and 9:"); num=scr.nextInt(); switch(num) { case 0: System.out.println("You entered ZERO"); break; case 1: System.out.println("You entered ONE"); break; case 2: System.out.println("You entered TWO"); break; case 3: System.out.println("You entered THREE"); break; case 4: System.out.println("You entered FOUR"); break; case 5: System.out.println("You entered FIVE"); break; case 6: System.out.println("You entered SIX"); break; case 7: System.out.println("You entered SEVEN"); break; case 8: System.out.println("You entered EIGHT"); break; case 9: System.out.println("You entered NINE"); break; default: System.out.println("wrong input"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number between 1 and 12:"); num=scr.nextInt(); switch(num) { case 1: System.out.println("You entered JANUARY"); break; case 2: System.out.println("You entered FEBURARY"); break; case 3: System.out.println("You entered MARCH"); break; case 4: System.out.println("You entered APRIL"); break; case 5: System.out.println("You entered MAY"); break; case 6: System.out.println("You entered JUNE"); break; case 7: System.out.println("You entered JULY"); break; case 8: System.out.println("You entered AUGUST"); break; case 9: System.out.println("You entered SEPTEMBER"); break; case 10: System.out.println("You entered OCTOBER"); break; case 11: System.out.println("You entered NOVEMBER"); break; case 12: System.out.println("You entered DECEMBER"); break; default: System.out.println("wrong input"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num; System.out.println("Enter any number between 1 and 7:"); num=scr.nextInt(); switch(num) { case 1: System.out.println("You entered SUNDAY"); break; case 2: System.out.println("You entered MONDAY"); break; case 3: System.out.println("You entered TUESDAY"); break; case 4: System.out.println("You entered WEDNESDAY"); break; case 5: System.out.println("You entered THURSDAY"); break; case 6: System.out.println("You entered FRIDAY"); break; case 7: System.out.println("You entered SATURDAY"); break; default: System.out.println("wrong input"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { char ch; Scanner scr=new Scanner(System.in); System.out.println("Enter any character "); ch=scr.next().charAt(0); switch(ch) { case 'a': System.out.println("Character is vowel"); break; case 'e': System.out.println("Character is vowel"); break; case 'i': System.out.println("Character is vowel"); break; case 'o': System.out.println("Character is vowel"); break; case 'u': System.out.println("Character is vowel"); break; default: System.out.println("character is consonent"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num1,num2,res; int value; System.out.println("Enter first number: "); num1=scr.nextInt(); System.out.println("Enter second number: "); num2=scr.nextInt(); System.out.println("Press 1 for addition"); System.out.println("Press 2 for subtraction"); System.out.println("Press 3 for division"); System.out.println("Press 4 for multilication"); System.out.println("Press 5 for EXIT"); value=scr.nextInt(); switch(value) { case 1: res=num1+num2; System.out.println("The sum is: "+res); break; case 2: res=num1-num2; System.out.println("The subtraction is: "+res); break; case 3: res=num1/num2; System.out.println("The division is: "+res); break; case 4: res=num1*num2; System.out.println("The multiplication is: "+res); break; default: System.exit(0); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int x=0,y=1,z,i,fac=1; int value; System.out.println("Press 1 for fibbonacci series"); System.out.println("Press 2 for factorial"); System.out.println("Press 3 for printing even series"); System.out.println("Press 4 for printing odd series"); System.out.println("Press 5 for EXIT"); value=scr.nextInt(); switch(value) { case 1: System.out.print("Fibbonacci series is:"); System.out.print(x+" "+y); for(i=1;i<=8;i++) { z=x+y; x=y; y=z; System.out.print(" "+z); } break; case 2: for(i=1;i<=5;i++) { fac=fac*i; } System.out.print("factorial of 5 is: "+fac); break; case 3: System.out.print("even series is: "); for(i=0;i<=10;i=i+2) { System.out.print(i+" "); } break; case 4: System.out.print("odd series is: "); for(i=1;i<=10;i=i+2) { System.out.print(i+" "); } case 5: System.exit(0); break; default: System.out.print("wrong input,Please try again"); } }//end of main }//end of class
import java.util.Scanner; public class switch_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int value,n; char a; int x=0,y=1,z,i,fac=1; System.out.println("Press 1 for even numbers"); System.out.println("Press 2 for odd numbers"); System.out.println("Press 3 for square of the number"); System.out.println("Press 4 for character series"); System.out.println("Press 5 for EXIT"); value=scr.nextInt(); switch(value) { case 1: System.out.println("Enter nth number: "); n=scr.nextInt(); System.out.println("even series is: "); for(i=0;i<=n;i=i+2) { System.out.print(i+" "); } break; case 2: System.out.println("Enter nth number: "); n=scr.nextInt(); System.out.println("odd series is: "); for(i=1;i<=n;i=i+2) { System.out.print(i+" "); } break; case 3: System.out.println("Enter nth number: "); n=scr.nextInt(); System.out.print((n*n)); break; case 4: System.out.println("Enter any character in lowercase: "); a=scr.next().charAt(0); for(i=97;a<=122;a++) { System.out.print(a+" "); } break; case 5: System.exit(0); break; default: { System.out.println("wrong input"); } } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=1;i<=10;i++) { System.out.print("*");; } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=1;i<=10;i++) { System.out.println("*");; } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=1;i<=6;i++) { System.out.println("\t*"); System.out.println("COMPUHELP\n"); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=0;i<=9;i++) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=9;i>=0;i--) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=5;i<=20;i++) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=45;i>=7;i--) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=1;i<=20;i+=2) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i; for(i=0;i<=20;i+=2) { System.out.print(i+" "); } }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num; System.out.println("Enter the limit "); num=scr.nextInt(); for(i=1;i<=num;i+=2) { System.out.print(i+" "); } }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num; System.out.println("Enter the limit "); num=scr.nextInt(); for(i=0;i<=num;i+=2) { System.out.print(i+" "); } }//end of main }//end of class
public class loop_statements { public static void main(String[] args) { int i,num; for(i=0;i<=50;i+=3) { System.out.print(i+" "); } }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num,a=0,b=1,res=0; System.out.println("Enter the limit "); num=scr.nextInt(); System.out.println(a+" "+b); for(i=0;res<=num;i++) { res=a+b; a=b; b=res; System.out.print(" "+res); } }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num,prod=1; System.out.println("Enter the limit "); num=scr.nextInt(); for(i=0;prod<=num;i++) { System.out.print(prod+" "); prod=prod*2; } }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num,fact=1; System.out.println("Enter the number whose factorial you want to print: "); num=scr.nextInt(); for(i=1;i<=num;i++) { fact=fact*i; System.out.print(i+"*"); } System.out.print("\b="+fact); }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num,sum=0; System.out.println("Enter the number whose sum of series you want to print: "); num=scr.nextInt(); for(i=1;i<=num;i++) { sum=sum+i; System.out.print(i+"+"); } System.out.print("\b="+sum); }//end of main }//end of class
import java.util.Scanner; public class loop_statements { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int m,n,i,res=1; System.out.println("Enter the value for m "); m=scr.nextInt(); System.out.println("Enter the value for n "); n=scr.nextInt(); for(i=1;i<=n;i++) { res=res*m; } System.out.print(res); }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=3;col++) { System.out.print("*"); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k=1; for(row=1;row<=3;row++) { for(col=1;col<=3;col++) { System.out.print(k); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=3;col++) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=3;col++) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k=1; for(row=1;row<=3;row++) { for(col=1;col<=3;col++) { System.out.print(k); k++; }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=1;col<=3;col++) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k=9; for(row=3;row>=1;row--) { for(col=1;col<=3;col++) { System.out.print(k); k--; }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=3;col>=1;col--) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=row;col++) { System.out.print("*"); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=1;col<=row;col++) { System.out.print("*"); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=row;col++) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=row;col++) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=3;col>=row;col--) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=3;col>=row;col--) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=row;col<=3;col++) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=3;row>=1;row--) { for(col=3;col>=row;col--) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k; for(row=1;row<=3;row++) { for(k=row;k>=2;k--) { System.out.print(" "); } for(col=3;col>=row;col--) { System.out.print("*"); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k; for(row=3;row>=1;row--) { for(k=2;k>=row;k--) { System.out.print(" "); } for(col=1;col<=row;col++) { System.out.print(col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col,k; for(row=1;row<=3;row++) { for(k=row;k>=2;k--) { System.out.print(" "); } for(col=row;col<=3;col++) { System.out.print(row); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; for(row=1;row<=3;row++) { for(col=1;col<=row;col++) { System.out.print("* "); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int i,j,k; for(i=1;i<=4;i++) { for(k=3;k>=i;k--) { System.out.print(" "); } for(j=1;j<=i;j++) { System.out.print("* "); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; //65 is ASCII value of A for(row=65;row<=67;row++) { for(col=65;col<=row;col++) { System.out.print((char)col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int row,col; //65 is ASCII value of A for(row=65;row<=67;row++) { for(col=67;col>=row;col--) { System.out.print((char)col); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
public class NestedForLoop { public static void main(String[] args) { int i,j,k; //65 is ASCII value of A for(i=65;i<=67;i++) { for(k=66;k>=i;k--) { System.out.print(" "); } for(j=65;j<=i;j++) { System.out.print((char)j); }//end of inner loop System.out.println(); }//end of outer loop }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i, m=0,n; System.out.println("Enter nth number: "); n=scr.nextInt(); while(m<=n) { System.out.print(m+" "); m++; } }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,m; System.out.println("Enter starting number: "); m=scr.nextInt(); while(m>=0) { System.out.print(m+" "); m--; } }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,n,cnt=1; System.out.println("Enter any number: "); n=scr.nextInt(); while(cnt<=10) { System.out.println(n+"*"+cnt+"="+(n*cnt)); cnt++; } }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,num,x=0,y=1,z=1; System.out.println("Enter any number: "); num=scr.nextInt(); System.out.print(x+" "+y); do { z=x+y; System.out.print(" "+z); x=y; y=z; } while(z<=(num-x)); }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num=1,m1,m2,m3; float avg=0; while(num<=5) { System.out.println("Enter your marks in maths:"); m1=scr.nextInt(); System.out.println("Enter your marks in english:"); m2=scr.nextInt(); System.out.println("Enter your marks in hindi:"); m3=scr.nextInt(); avg=(m1+m2+m3)/3; System.out.println("The average marks is: "+avg); num++; } }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num=0,rev=0; System.out.println("Enter any number: "); num=scr.nextInt(); System.out.println("The reverse of the number is: "); while(num>=1) { rev=num%10; num=num/10; System.out.print(rev); } }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int i,m,n,res=1,count=1; System.out.println("Enter the value for m: "); m=scr.nextInt(); System.out.println("Enter the value for n: "); n=scr.nextInt(); while(count<=n) { res=res*m; count++; } System.out.println("the result is: +res); }//end of main }//end of class
import java.util.Scanner; public class WhileLoop { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int num=0, fac=1; System.out.println("Enter any number: "); num=scr.nextInt(); System.out.println("The factorial of the number is: "); while(num>=1) { fac=fac*num; System.out.print(num+"*"); num--; } System.out.println("\b="+fac); }//end of main }//end of class
//program to accept a character from the user import java.util.Scanner; public class AcceptCharacter { public static void main(String[] args) { Scanner scr=new Scanner(System.in); char ch; System.out.println("Enter any character: "); ch=scr.next().charAt(0); System.out.println("The character is "+ch); }//end of main }//end of class
//Program to accept a character in lower case and display it in uppercase. import java.util.Scanner; public class AcceptCharacter { public static void main(String[] args) { Scanner scr=new Scanner(System.in); char ch; int x; System.out.println("Enter any character: "); ch=scr.next().charAt(0); x=ch; x=x-32; ch=(char)x; System.out.println("The character is "+ch); }//end of main }//end of class
//program to accept a character from the user and display its ASCII value. import java.util.Scanner; public class AcceptCharacter { public static void main(String[] args) { Scanner scr=new Scanner(System.in); char ch; System.out.println("Enter any character: "); ch=scr.next().charAt(0); System.out.println("The ASCII value of "+ch+" is "+(int)ch); }//end of main }//end of class
// program to accept a character in uppercase and display it in lowercase. import java.util.Scanner; public class AcceptCharacter { public static void main(String[] args) { Scanner scr=new Scanner(System.in); char ch; int x; System.out.println("Enter any character: "); ch=scr.next().charAt(0); x=ch; x=x+32; ch=(char)x; System.out.println("The character is "+ch); }//end of main }//end of class
//program to display the ASCII values of 0 and 9. public class AcceptCharacter { public static void main(String[] args) { char ch1,ch2; ch1='0'; ch2='9'; System.out.println("The ASCII value of 0 is "+(int)ch1); System.out.println("The ASCII value of 9 is "+(int)ch2); }//end of main }//end of class
//program to display the ASCII values fron 0 to 9. public class AcceptCharacter { public static void main(String[] args) { char ch; ch='0'; int i; for(i=0;i<=9;i++) { System.out.println("The ASCII of "+ch+" is "+(int)ch); ch++; } }//end of main }//end of class
/*program to display the ASCII values of all characters from A to Z.*/ public class AcceptCharacter { public static void main(String[] args) { char ch; ch='A'; int i; for(i=1;i<=26;i++) { System.out.println("The ASCII of "+ch+" is "+(int)ch); ch++; } }//end of main }//end of class
/* program to let the user press any key on the keyboard until x
but count only how many upper case character keys are pressed on the keyboard?*/ import java.util.Scanner; public class AcceptCharacter { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int keys=0; char ch; System.out.println("Press any key including upper case alphabets: "); while(true) { ch=scr.next().charAt(0); if((ch>=65)&&(ch<=90)) { keys++; } if((ch=='x')||(ch=='X')) { break; } }//end of while loop System.out.println("The uppercase character keys are pressed ("+keys+") Times"); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[]=new int[5]; int i; for(i=0;i<5;i++) { System.out.println("Enter array elements "); arr[i]= scr.nextInt(); } for(i=0;i<arr.length;i++) { System.out.println("Array elements are: "+arr[i]); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[]=new int[5]; int i,len; len=arr.length; for(i=0;i<len;i++) { System.out.println("Enter array elements "); arr[i]= scr.nextInt(); } System.out.println("Array elements in Reverse order are: "); for(i=len-1;i>=0;i--) { System.out.print(" "+arr[i]); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[]=new int[5]; int arr1[]=new int[5]; int i,len; len=arr.length; for(i=0;i<len;i++) { System.out.println("Enter array elements "); arr[i]= scr.nextInt(); } System.out.println("Copied elements are : "); for(i=0;i<len;i++) { arr1[i]=arr[i]; System.out.print(" "+arr1[i]); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[]=new int[5]; int arr1[]=new int[5]; int i,len,j; len=arr.length; for(i=0;i<len;i++) { System.out.println("Enter array elements "); arr[i]= scr.nextInt(); } System.out.println("Copied elements are : "); j=0; for(i=4;i>=0;i--) { arr1[j]=arr[i]; System.out.println("Element is "+arr1[j]); j++; } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[]=new int[5]; int i,sum=0; for(i=0;i<arr.length;i++) { System.out.println("Enter array elements "); arr[i]= scr.nextInt(); } System.out.println("Sum of Array elements is : "); for(i=0;i<arr.length;i++) { sum=sum+arr[i]; System.out.print(arr[i]+"+"); } System.out.print("\b="+sum); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int arr2[]=new int[5]; int sum[]=new int[5]; int i; System.out.println("Enter elements into first array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } System.out.println("Enter elements into second array: "); for(i=0;i<arr1.length;i++) { arr2[i]= scr.nextInt(); } System.out.println("Sum of Two Array elements is : "); for(i=0;i<arr1.length;i++) { sum[i] =arr1[i]+arr2[i]; System.out.print(sum[i]+" "); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int arr2[]=new int[5]; int sum[]=new int[5]; int i; System.out.println("Enter elements into first array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } System.out.println("Enter elements into second array: "); for(i=0;i<arr1.length;i++) { arr2[i]= scr.nextInt(); } System.out.println("Sum of Two Array elements is : "); for(i=0;i<arr1.length;i++) { sum[i] =arr1[i]-arr2[i]; System.out.print(sum[i]+" "); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int i,large=0,loc=0; System.out.println("Enter elements into first array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } System.out.println("Array elements are : "); for(i=0;i<arr1.length;i++) { System.out.print(arr1[i]+" "); if(arr1[i]>large) { large=arr1[i]; loc=i+1; } } System.out.println("The greatest element is "+large+" at location "+loc); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int i,small,loc=0; System.out.println("Enter elements into an array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } small=arr1[0]; System.out.println("Array elements are : "); for(i=1;i<arr1.length;i++) { System.out.print(arr1[i]+" "); if(arr1[i]<small) { small=arr1[i]; loc=i+1; } } System.out.println(); System.out.println("The smallest element is "+small+" at location "+loc); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int i,j,temp; System.out.println("Enter elements into an array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } for(i=0;i<=4;i++) { for(j=i+1;j<5;j++) { if(arr1[i]>arr1[j]) { temp=arr1[i]; arr1[i]=arr1[j]; arr1[j]=temp; } } } System.out.println("Sorted Array Elements are(Ascending Order) : "); for(i=0;i<arr1.length;i++) { System.out.println(arr1[i]); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int i,j,temp; System.out.println("Enter elements into an array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } for(i=0;i<=4;i++) { for(j=i+1;j<5;j++) { if(arr1[i]<arr1[j]) { temp=arr1[i]; arr1[i]=arr1[j]; arr1[j]=temp; } } } System.out.println("Sorted Array Elements are(Descending Order) : "); for(i=0;i<arr1.length;i++) { System.out.println(arr1[i]); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr1[]=new int[5]; int i,n,flag=0; System.out.println("Enter elements into an array: "); for(i=0;i<arr1.length;i++) { arr1[i]= scr.nextInt(); } System.out.println("Array Elements are : "); for(i=0;i<arr1.length;i++) { System.out.println(arr1[i]); } System.out.println("Enter any number which you want to search: "); n= scr.nextInt(); for(i=0;i<=4;i++) { if(arr1[i]==n) { flag=1; System.out.println("The number is "+arr1[i]+" found at "+(i+1)+" location"); } } if(flag==0) { System.out.println("Number is not found"); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][3]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j = 0; j < col; j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Array Elements are : "); for(i=0;i<row;i++) { for (j = 0; j < col; j++) { System.out.print(arr[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Copied Array Elements are : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j]=arr[i][j]; System.out.print(arr1[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Reverse copy of Array Elements are : "); for(i=row-1;i>=0;i--) { for (j = col - 1; j >= 0; j--) { arr1[i][j] = arr[i][j]; System.out.print(arr1[i][j] + " "); } System.out.println(); } /* int x=1; int y=1; System.out.println("Reverse copy of Array Elements are : "); for(i=0;i<row;i++) { y++; for (j=0;j<col;j++) { arr1[i][j]=arr[x][y]; System.out.print(arr1[i][j]+" "); y--; } System.out.println(); x=0; }*/ }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Copy of Array Elements are : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j] = arr[i][j]; System.out.print(arr1[i][j] + " "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Reverse of Array Elements are : "); for(i=row-1;i>=0;i--) { for (j = col - 1; j >= 0; j--) { System.out.print(arr[i][j] + " "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col,sum=0; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Sum of Array Elements are : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { sum = sum+arr[i][j]; System.out.print(arr[i][j]+"+"); } } System.out.println("\b="+sum); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int sum[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into first Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Enter elements into Second Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j] = scr.nextInt(); } } System.out.println("Sum of two matrices is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { sum[i][j] = arr[i][j]+arr1[i][j]; System.out.print(sum[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int sub[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into first Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Enter elements into Second Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j] = scr.nextInt(); } } System.out.println("Diffrence between two matrices is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { sub[i][j] = arr[i][j]-arr1[i][j]; System.out.print(sub[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int arr1[][]=new int[2][2]; int div[][]=new int[2][2]; int i,j,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into first Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Enter elements into Second Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j] = scr.nextInt(); } } System.out.println("Division of two matrices is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { div[i][j] = arr[i][j]/arr1[i][j]; System.out.print(div[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[3][3]; int arr1[][]=new int[3][3]; int ans[][]=new int[3][3]; int i,j,k,row,col; row=arr.length; col=arr[0].length; System.out.println("Enter elements into first Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Enter elements into Second Matrix: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr1[i][j] = scr.nextInt(); } } System.out.println("Multiplication of two matrices is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { ans[i][j]=0; for(k=0;k<3;k++) { ans[i][j]+=arr[i][k]*arr1[k][j]; }//end of k loop System.out.print(ans[i][j]+" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col,large=0,rloc=0,cloc=0; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Array Elements are : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { System.out.print(arr[i][j] +" "); } System.out.println(); } for(i=0;i<row;i++) { for (j=0;j<col;j++) { if(arr[i][j]>large) { large=arr[i][j]; rloc=i+1; cloc=j+1; } } } System.out.println("The greatest element is "+large+" and present at ["+rloc+"] row and ["+cloc+"] column"); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col,small=0,rloc=0,cloc=0; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Array Elements are : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { System.out.print(arr[i][j] +" "); } System.out.println(); } small=arr[0][0]; for(i=0;i<2;i++) { for(j=0;j<2;j++) { if(arr[i][j]<small) { small=arr[i][j]; rloc=i+1; cloc=j+1; } } } System.out.println("The smallest element is "+small+" and present at ["+rloc+"] row and ["+cloc+"] column"); }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col,small=0,rloc=0,cloc=0; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Matrix is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { System.out.print(arr[i][j] +" "); } System.out.println(); } System.out.println("Tranpose of Matrix is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { System.out.print(arr[j][i] +" "); } System.out.println(); } }//end of main }//end of class
import java.util.Scanner; public class MyArray { public static void main(String[] args) { Scanner scr=new Scanner(System.in); int arr[][]=new int[2][2]; int i,j,row,col,n,flag=0; row=arr.length; col=arr[0].length; System.out.println("Enter elements into an array: "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { arr[i][j] = scr.nextInt(); } } System.out.println("Matrix is : "); for(i=0;i<row;i++) { for (j=0;j<col;j++) { System.out.print(arr[i][j] +" "); } System.out.println(); } System.out.println("Enter the number which you want to search : "); n=scr.nextInt(); for(i=0;i<row;i++) { for (j=0;j<col;j++) { if (arr[i][j] == n) { flag = 1; System.out.println("Number is found at " + (i + 1) + " row and " + (j + 1) + " col"); }//end of if } //end of j loop }//end of i loop if(flag==0) { System.out.println("Number is not found"); } }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void sum() { int num1,num2,num3,num4,res; Scanner scr=new Scanner(System.in); System.out.println("Enter first number"); num1=scr.nextInt(); System.out.println("Enter second number"); num2=scr.nextInt(); System.out.println("Enter third number"); num3=scr.nextInt(); System.out.println("Enter fourth number"); num4=scr.nextInt(); res=num1+num2+num3+num4; System.out.println("Sum is "+res); }//end of sum public static void main(String[] args) { FunctionPractice fp=new FunctionPractice(); fp.sum(); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { int num1,num2,res; static Scanner scr=new Scanner(System.in); void input() { System.out.println("Enter first number"); num1=scr.nextInt(); System.out.println("Enter second number"); num2=scr.nextInt(); } //end of input void sum() { res=num1+num2; System.out.println("Sum is "+res); }//end of sum void subtract() { if(num1>num2) { res = num1 - num2; } else { res=num2-num1; } System.out.println("Subtraction is "+res); }//end of subtract void multiply() { res=num1*num2; System.out.println("Multiplication is "+res); }//end of multiply void divide() { res=num1/num2; System.out.println("Division is "+res); }//end of divide public static void main(String[] args) { FunctionPractice fp=new FunctionPractice(); char ch; System.out.println("Press + for addition"); System.out.println("Press - for subtraction"); System.out.println("Press * for multiplication"); System.out.println("Press / for division"); System.out.println("Enter your choice "); ch=scr.next().charAt(0); fp.input(); switch (ch) { case '+': fp.sum(); break; case '-': fp.subtract(); break; case '*': fp.multiply(); break; case '/': fp.divide(); break; default: System.out.println("Wrong input! Try again."); } }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { static void odd(int n1) { int i; System.out.println("The Odd Series is: "); for(i=1;i<=n1;i+=2) { System.out.print(i+" "); } } public static void main(String[] args) { Scanner scr=new Scanner(System.in); int n; System.out.println("Enter the nth number "); n=scr.nextInt(); //no need to create the object for static function odd(n); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { static void even(int n1) { int i; System.out.println("The Even Series is: "); for(i=0;i<=n1;i+=2) { System.out.print(i+" "); } } public static void main(String[] args) { Scanner scr=new Scanner(System.in); int n; System.out.println("Enter the nth number "); n=scr.nextInt(); //no need to create the object for static function even(n); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void display(char ch1,int n1) { int i; System.out.println("Series is: "); for(i=1;i<=n1;i++) { System.out.print(ch1); }//end of loop }//end of display function public static void main(String[] args) { Scanner scr=new Scanner(System.in); FunctionPractice fp=new FunctionPractice(); char ch; int n; System.out.println("Enter the character"); ch=scr.next().charAt(0); System.out.println("Enter the nth number "); n=scr.nextInt(); fp.display(ch,n); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void series(int n1,int n2) { int i; System.out.println("The Series is: "); for(i=n1;i<=n2;i++) { System.out.print(i+" "); }//end of loop }//end of display function public static void main(String[] args) { Scanner scr=new Scanner(System.in); FunctionPractice fp=new FunctionPractice(); int start,stop; System.out.println("Enter the starting number of the series"); start=scr.nextInt(); System.out.println("Enter the ending number of the series"); stop=scr.nextInt(); fp.series(start,stop); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void pos_neg(int n) { if(n>0) { System.out.println("Number is positive"); }//end of if else if(n<0) { System.out.println("Number is negative"); } else { System.out.println("Number is zero"); } }//end of display function public static void main(String[] args) { Scanner scr=new Scanner(System.in); FunctionPractice fp=new FunctionPractice(); int num; System.out.println("Enter the number : "); num=scr.nextInt(); fp.pos_neg(num); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void fibonacci(int n) { int i,j=0,k=1,m; System.out.print(j+" "+k); for(i=1;i<=n;i++) { m=j+k; j=k; k=m; if(m<=n) System.out.print(" "+m); }//end of loop }//end of function public static void main(String[] args) { Scanner scr=new Scanner(System.in); FunctionPractice fp=new FunctionPractice(); int num; System.out.println("Enter any number for ending value: "); num=scr.nextInt(); fp.fibonacci(num); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void seriesSum(int n) { int j = 1; int sum = 0; System.out.print("SERIES = "); for (int i = 1; i <= n; i++) { j = i * i; sum = sum + j; System.out.print(j); if(i<n) { System.out.print(" + "); } } System.out.print(" = " + sum); } public static void main(String[] args) { int num; System.out.print("Enter the number whos series sum you want "); Scanner sc = new Scanner(System.in); num = sc.nextInt(); FunctionPractice fp=new FunctionPractice(); fp.seriesSum(num); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { int factorialFunction(int num) { int fact = 1; for (int i = num; i >= 1; i--) { fact = fact * i; } return fact; } public static void main(String[] args) { System.out.println("Enter the number whose factorial you want :"); Scanner sc = new Scanner(System.in); int number; number = sc.nextInt(); FunctionPractice fpf = new FunctionPractice(); int result = fpf.factorialFunction(number); System.out.println("The factorial is : " + result); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { void swappingNumber(int num1, int num2) { int temp; temp = num1; num1 = num2; num2 = temp; System.out.println("The numbers after swapping are : " + num1 +" "+ num2); } public static void main(String[] args) { System.out.println("Enter two numbers "); Scanner sc = new Scanner(System.in); int number1, number2; number1 = sc.nextInt(); number2 = sc.nextInt(); System.out.println("The numbers before swapping are : " + number1 +" "+ number2); FunctionPractice fp = new FunctionPractice(); fp.swappingNumber(number1, number2); }//end of main }//end of class
import java.util.Scanner; public class FunctionPractice { int factorialFunction(int num) { int fact = 1; if (num == 0 || num == 1) return 1; else fact = num * factorialFunction(num - 1); return fact; } public static void main(String[] args) { System.out.println("Enter the number whose factorial you want :"); Scanner sc = new Scanner(System.in); int number; number = sc.nextInt(); FunctionPractice fp = new FunctionPractice(); int result = fp.factorialFunction(number); System.out.println("The factorial is : " + result); }//end of main }//end of class
import java.util.Scanner; class Maths { private int num1,num2,res; Scanner scr=new Scanner(System.in); public void input() { System.out.println("Enter first number: "); num1=scr.nextInt(); System.out.println("Enter second number: "); num2=scr.nextInt(); } public void sum() { res=num1+num2; System.out.println("Sum is "+res); } };//end of class public class OopPracticeAssignments { public static void main(String[] args) { Maths mt=new Maths(); mt.input(); mt.sum(); }//end of main }//end of class
import java.util.Scanner; class Student { private int rollno; private float marks[]=new float[2],per,sum; Scanner scr=new Scanner(System.in); public void get_data() { int i; sum=0; System.out.println("Enter rollno "); rollno=scr.nextInt(); for(i=0;i<2;i++) { System.out.println("Enter marks "); marks[i]=scr.nextInt(); sum=sum+marks[i]; } } public void percent() { per=sum/2; System.out.println("Percentage is "+per); } };//end of class public class OopPracticeAssignments { public static void main(String[] args) { Student st[]=new Student[2]; int i; st[0]=new Student(); st[1]=new Student(); for(i=0;i<2;i++) { st[i].get_data(); System.out.println("Percentage of student "+(i+1)); st[i].percent(); System.out.println("----------------------------------\n"); } }//end of main }//end of class
import java.util.Scanner; class Demo2 { private int num; Scanner scr=new Scanner(System.in); public void get_data() { System.out.println("Enter number "); num=scr.nextInt(); } public void sum(Demo2 dm) { int res; res=num+dm.num; System.out.println("Sum is "+res); } };//end of class public class OopPracticeAssignments { public static void main(String[] args) { Demo2 d1=new Demo2(); Demo2 d2=new Demo2(); d1.get_data(); d2.get_data(); d1.sum(d2); }//end of main }//end of class
import java.util.Scanner; class Demo2 { int num; Scanner scr=new Scanner(System.in); void get_data() { System.out.println("Enter number "); num=scr.nextInt(); } void sum(Demo2 dm) { int res; res=num+dm.num; System.out.println("Sum is "+res); } };//end of class public class OopPracticeAssignments { public static void main(String[] args) { Demo2 d1=new Demo2(); Demo2 d2=new Demo2(); d1.get_data(); d2.get_data(); d1.sum(d2); }//end of main }//end of class
import java.util.Scanner; class Demo { Scanner scr=new Scanner(System.in); private int num1,num2,num3; public void max() { System.out.println("Enter first number "); num1=scr.nextInt(); System.out.println("Enter second number "); num2=scr.nextInt(); System.out.println("Enter third number "); num3=scr.nextInt(); if(num1>num2 && num1>num3) { System.out.println("num1 is greater "); } else if(num2>num1 && num2>num3) { System.out.println("num2 is greater "); } else { System.out.println("num3 is greater "); } } }//end of class public class OopPracticeAssignments { public static void main(String[] args) { Demo dm=new Demo(); dm.max(); }//end of main }//end of class
class MyRectangle { int length; int breath; int areaOfRectangle; public MyRectangle() { length = 10; breath = 20; } public void area() { System.out.println("The length is : " + length); System.out.println("The breath is : " + breath); areaOfRectangle = length * breath; System.out.println("The area is : " + areaOfRectangle); } }//end of class public class OopPracticeAssignments { public static void main(String[] args) { MyRectangle myRect = new MyRectangle(); myRect.area(); }//end of main }//end of class
class MyRectangle { int length; int breath; int areaOfRectangle; public MyRectangle(int l, int b) { length = l; breath = b; } public void area() { System.out.println("The length is : " + length); System.out.println("The breath is : " + breath); areaOfRectangle = length * breath; System.out.println("The area is : " + areaOfRectangle); }//end of function }//end of class public class MyJavaProgram { public static void main(String[] args) { MyRectangle myRect = new MyRectangle(10, 20); myRect.area(); MyRectangle myRect2 = new MyRectangle(56, 19); myRect2.area(); }//end of function }//end of class
class MyRectangle { int length; int breath; public MyRectangle() { length = 10; breath = 20; System.out.println("The length using default constructor is : " + length); System.out.println("The breath usin default constructor is : " + breath); } public MyRectangle(int l, int b) { length = l; breath = b; System.out.println("The length using parametrised constructor is : " + length); System.out.println("The breath using parametrised constructor is : " + breath); }//end of function }//end of class public class MyJavaProgram { public static void main(String[] args) { MyRectangle myRect = new MyRectangle(); MyRectangle myRect2 = new MyRectangle(56, 19); }//end of function }//end of class
class MyRectangle { int length; int breath; int areaOfRectangle; public MyRectangle() { length = 23; breath = 56; } public void copyValue(MyRectangle my) { length = my.length; breath = my.breath; } public void area() { System.out.println("The length is : " + length); System.out.println("The breath is : " + breath); areaOfRectangle = length * breath; System.out.println("The area is : " + areaOfRectangle); }//end of function }//end of class public class MyJavaProgram { public static void main(String[] args) { MyRectangle myRect = new MyRectangle(); myRect.area(); MyRectangle myRect2 = new MyRectangle(); myRect.copyValue(myRect2); myRect2.area(); }//end of main }//end of class
class Maths { int num1; int num2; float num3; float num4; /* public void sum(int n1, int n2) { num1 = n1; num2 = n2; int sumOfInt = num1 + num2; System.out.println("The sum of integers values is : " + sumOfInt); } */ public void sum(float n3, float n4) { num3 = n3; num4 = n4; float sumOfFloat = num3 + num4; System.out.println("The sum of integers values is : " + sumOfFloat); }//end of sum }//end of class public class MyFunctionOverloading { public static void main(String[] args) { Maths mt = new Maths(); mt.sum(10, 20); mt.sum(34.5f, 78.6f); }//end of main }//end of class
class Shape { int length; int breath; int side; public void area(int l, int b) { length = l; breath = b; int areaOfRect = length * breath; System.out.println("The area of the reactangle is : " + areaOfRect); } public void area(int s) { side = s; int areaOfSquare = side*side; System.out.println("The area of the reactangle is : " + areaOfSquare); }//end of function }//end of class public class MyFunctionOverloading { public static void main(String[] args) { Shape s1 = new Shape(); s1.area(10, 20); s1.area(5); }//end of main }//ecd of class
class StaticDemo { static int n = 0; public StaticDemo() { n++; System.out.println("Object " + n + " created"); }//end of function }//end of class public class staticFunction { public static void main(String[] args) { StaticDemo sd1 = new StaticDemo(); StaticDemo sd2 = new StaticDemo(); StaticDemo sd3 = new StaticDemo(); }//end of main }//end of class
class Rectangle { int l; int b; static int n = 0; public Rectangle() { n++; System.out.println("Rectangle " + n + " is created"); } public void area(int length, int breath) { l = length; b = breath; int area; area = l * b; System.out.println("The area of rectangle is :" + area); }//end of function }//end of class public class staticFunction { public static void main(String[] args) { Rectangle rect = new Rectangle(); Rectangle rect1 = new Rectangle(); Rectangle rect2 = new Rectangle(); rect.area(10, 40); rect1.area(89, 56); rect2.area(13, 59); }//end of main }//end of clas
class MyRectangle { static int length; static int breath; int areaOfRectangle; public static void init() { length=10; breath=20; } public void area() { System.out.println("The length is : " + length); System.out.println("The breath is : " + breath); areaOfRectangle = length * breath; System.out.println("The area is : " + areaOfRectangle); }//end of function }//end of class public class MyJavaProgram { public static void main(String[] args) { MyRectangle myRect = new MyRectangle(); MyRectangle.init(); myRect.area(); }//end of main }//end of class