Java Programs For Isc
Java Programs For Isc
Java Programs For Isc
import java.io.*; class Num2Words { public static void main(String args[])throws IOException//main function { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter any Number(less than 99)"); int amt=Integer.parseInt(br.readLine());//accepting number int z,g; int z,g; String x[ ]={" ","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eig hteen","Nineteen"}; String x1[ ]={"","One","Two","Three","Four","Five","Six","Seven","Eight","Nine"}; String x2[]={"","Twenty","Thirty","Fourty","Fifty","Sixty","Seventy","Eighty","Ninety"}; z=amt%10;//finding the number in words g=amt/10; if(g!=1) System.out.println(x2[g-1]+" "+x1[z]); else System.out.println(x[amt-9]); } }
Variable description Variable z g x[] x1[] x2[] amt Data Type int int string string string int Description amt%10 amt%10 Storing number in words Storing number in words Storing number in words Inputted number
Output
Enter any Number(less than 99) Input:- 88 Output:- Eighty Eight
{ BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter 1st term"); a=Integer.parseInt(br.readLine());//accepting 1st term System.out.println("Enter Common difference"); d=Integer.parseInt(br.readLine());//accepting common difference System.out.println("Enter no.of terms"); int n=Integer.parseInt(br.readLine()); //accepting no. of terms nTHTerm(n); Sum(n); showSeries(n); }}
Variable description
Variable Data Type Description
a d n i
Output
Enter 1st term 21 Enter Common difference 5 Enter no.of terms 8 Series 21.0 26.0 31.0 36.0 41.0 46.0 51.0 56.0 Sum : 308.0
{ System.out.print(' '+"\t"); count--; } for(i=1;i<7;i++) { while(b>0 && d<=days[month-1]) { System.out.print(d+"\t"); d++;b--; } b=7; System.out.println(" "); } } }
Variable description
Variable i count b d month year w days month1 Data Type int int int int int int String String String Description To run the loop Counter variable Week counter Day counter Input Month Input Year Week days Array storing days Array storing months
Output Enter month 6 Enter Year 2012 =============The Calendar of June 2012is =============== S 3 10 M 4 11 T 5 12 W 6 13 T 7 14 F 1 8 15 S 2 9 16
17 24
18 25
19 26
20 27
21 28
22 29
23 30
Variable description
Variable Data Type Description
p q
int int
int
n = -1; do { m[i][j] = c++; n++; i--; } while(n<s-2); n= n - 2; } for(i=0; i<s; i++) { for(j=0; j<s; j++) { System.out.print(m[i][j] + " "); } System.out.println(); } } }
Variable description
Variable Data Type Description
m[] n
int int
To store the matrix To store a value in spiral matrix To store some value Counter variable Matrix for rows Matrix for columns
s c i j
Output 1 2 3 4 12 0 0 5
11 0 0 6 10 9 8 7
Variable description
Variable Data Type Description
n arr num
Input Dimensions Magic square matrix Loop variable for magic square
r c
int int
Output enter the dimension of magical square= 11 68 81 94 107 120 1 14 27 40 53 66 80 93 106 119 11 13 26 39 52 65 67 92 105 118 10 12 25 38 51 64 77 79 104 117 9 22 24 37 50 63 76 78 91 116 8 21 23 36 49 62 75 88 90 103 7 20 33 35 48 61 74 87 89 102 115 19 32 34 47 60 73 86 99 101 114 6 31 44 46 59 72 85 98 100 113 5 18
while( l<=u && flag == -1) { m = (l+u)/2; if(a[m] == v) flag = m; else if(a[m] < v) l = m+1; else u = m-1; } if(flag== -1 ) System.out.println("not found"); else System.out.println(v+" found at position - "+flag); } public static void main(String args[]) throws IOException//main function { BinarySearch obj = new BinarySearch(10); obj.input(); obj.display(); System.out.println("enter no. to be searched -"); int v = Integer.parseInt(br.readLine());//accepting integer to be searched by Binary search obj.search(v); } }
Variable description
Variable n i a[ ] nn v flag l u m Data Type int int int int int int int int int Description Array length To run the loop Input array Parameter in constructor Search element Flag value Lower element Upper element Middle Index
{ if(a[j]<a[min])min =j; } if(min!=i) { temp = a[i]; a[i] =a[min]; a[min] = temp; } } } public static void main(String args[]) throws IOException//main function { SelectionSort x = new SelectionSort(5); x.input(); System.out.print("Before sorting - "); x.display(); System.out.print("After sorting - "); x.sort(); x.display(); } }
Variable description
Variable Data Type Description
n i a[] nn j temp
Length of the array To run the loop Inputted array Parameter in constructor Sort index Temporary storage
min
int
Minimum value
public static void main(String args[]) throws IOException//main function { BubbleSort x = new BubbleSort(5); x.input(); System.out.print("Before sorting - "); x.display(); System.out.print("After sorting - "); x.sort(); x.display(); } }
Variable description
Variable Data Type Description
n i a[] nn j temp
Length of the array To run the loop Inputted array Parameter in constructor Sort index Temporary storage
Variable description
Variable Data Type Description
n i a[ ] nn no temp c
Length of the array To run the loop Array storing binary number Parameter in constructor Inputted number Temporary storage Counter variable
{ Day2Date obj = new Day2Date(); System.out.println( "Enter day no = "); //accepting day no. int n = Integer.parseInt(br.readLine()); System.out.println( "Enter year = ");//accepting year int yr = Integer.parseInt(br.readLine()); obj.calc(n,yr); }}
Variable description
Variable Data Type Description
n yr a[] m[] t s d
Day number Year Array storing day Array storing month Array index Array index Calculating day to date
Output Enter day no = 123 Enter year = 2009 Output: 3rdMay , 2009
Variable description
Variable
Data Type
Description
i s
int String
Variable description
Variable Data Type Description
i a1 l p freq ii a b str
To run the loop Instance variable To calculate the length of string Instance variable Frequency of characters To run the loop Character at index i) Character at index ii) Inputted String
Output
enter string Bastab Dey Output:- Bastab Dey B occurs 1 times a occurs 2 times s occurs 1 times t occurs 1 times a occurs 2 times b occurs 1 times occurs 1 times D occurs 1 times e occurs 1 times y occurs 1 times
Variable description
Variable s look flag Data Type String String char[ ] Description Inputted string To find the certain word in the inputted string To store a value
Word found
Variable description
Variable Data Type Description
i a ch
To run the loop To calculate range To calculate the last index of the string
s d
String int
Output In the method call of decode.main( ) enter the string(s) and the decoding value. Suppose entered string is COMPUTER and the decoding value is -5. Hence output, XPNQVUFS Suppose entered string is COMPUTER and the decoding value is 5. Hence output, Hence output, HZX[`_P]
} } public void display()//function to display the rearranged string { System.out.println(); for(int i=0;i<l;i++) { System.out.print(c[i]); } } public static void main(String args[]) throws IOException//main function { Alpha obj = new Alpha(); obj.readword(); obj.arrange(); obj.display(); } }
Variable description
Variable str l c i j temp Data Type String int char[ ] int int char Description Inputted string To calculate string length Character array To run the loop To run the loop Temporary storage
Variable description
Variable a z y x
Description To enter a sentence To calculate the length of the entered string To run the loop Incrementing the value
Output
Variable description
Variable a z Data Type String Buffer int Description To store the string To run the loop and to replace all the vowels with *.
Original String -you did not gain a percentage New String -y** d*d n*t g**n * p*rc*nt*g*
Variable description
Variable Data Type Description
i j m[ ]
To run the loop To run the loop To store the elements of the cells and display it
Output Enter the numbers one by one 20 25 26 21 24 23 27 32 14 56 89 90 23 21 74 25 The elements in the cells are: 20 25 26 21 24 23 27 32 14 56 89 90 23 21 74 25
Variable description
Variable Data Type Description
a x y z sum
Input array Run the loop Run the loop Input element Sum of all elements
Output
Enter the array 46 46 234 67 84 52 12 45 68 74 13 65 74 96 100 23 74 56 64 33 34 10 23 69 98 Array: 46 46 234 67 84 52 12 45 68 74 13 65 74 96 100 23 74 56 64 33 34 10 23 69 98 Sum of array elements=1560
3)
4)
import java.io.*; public class arr_product { public static void main(String args[])throws IOException { BufferedReader ob=new BufferedReader (new InputStreamReader(System.in)); int i; int a[]=new int[5]; int b[]=new int[5]; int c[]=0; for(i=0; i<5; i++) { a[i]= Integer.parseInt(ob.readLine()); b[i]= Integer.parseInt(ob.readLine()); } for(i=0; i<5; i++) { c[i]=a[i]*b[i]; } for(i=0; i<5; i++) System.out.println(c[i]); } }
Variable description
Variable Data Type Description
a[ ] b[ ] c[ ] i
To store 1st array To store 2nd array To calculate the product of two arrays To run the loop
Variable description
Variable Data Type Description
a x y z sum
Input array Run the loop Run the loop Input element Sum of all elements
Output
Enter the array 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Array10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 sum of column1 is 64 sum of column2 is 68 sum of column3 is 72 sum of column4 is 76
Variable description
Variable n i Data Type int int Description Entered range To run the loop
Output In the method call box enter the value of n. Suppose entered value of n is 7. Then, output:2, 9, 28, 65, 126, 217, 344, 513,
24)Wap to find the grade of steel samples considering the following conditions:I. Tensile strength>=700 kgf/cm^2 II. Rockwell hardness>=200 III. Carbon content <=6% When conditions I), II), III) are satisfied then the grade is A When conditions I) and II) are satisfied then the grade is B When conditions I) and III) are satisfied then the grade is C When conditions II) and III) are satisfied then the grade is D When conditions I) or II) or III) are satisfied then the grade is E, otherwise grade F
import java.io.*; public class steel_sample { public static void main(String args[])throws IOException { int rh,ts,cc; BufferedReader ob=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the tensile strength in kgf/cm^2"); ts=Integer.parseInt(ob.readLine()); System.out.println("Enter the rockwell hardness"); rh=Integer.parseInt(ob.readLine()); System.out.println("Enter the carbon content in percentage"); cc=Integer.parseInt(ob.readLine()); if(ts>=700 && rh>=200 && cc<=6) System.out.println(" GRADE A"); else if(ts>=700 && rh>=200) System.out.println(" GRADE B"); else if(ts>=700 && cc<=6) System.out.println(" GRADE C"); else if(rh>=200 && cc<=6) System.out.println(" GRADE D"); else if(ts>=700 || rh>=200 || cc<=6) System.out.println(" GRADE E"); else System.out.println(" GRADE F"); }}
Variable description
Variable Data Type Description
rh ts cc
To store the rockwell hardness To store the tensile strength To store the carbon content in percentage
Output
Enter the tensile strength in kgf/cm^2 700 Enter the rockwell hardness 200 Enter the carbon content in percentage 6 Output:GRADE A
import java.io.*; class Pascal { public void pascalw()throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter a no."); int n=Integer.parseInt(br.readLine()); int [ ] pas = new int [n+1]; pas[0] = 1; for (int i=0; i<n; i++) { for (int j=0; j<=i; ++j) System.out.print(pas[j]+" "); System.out.println( ); for (int j=i+1; j>0; j--) pas[j]=pas[j]+pas[j-1]; } } }
Variable description
Variable Data Type Description
n pas[] i j
Output
Enter a no. Input:- 5 Output:1 11 121 1331 14641