Skip to content

Commit 70d2c91

Browse files
committed
Pattern and linear search example
1 parent 926fb28 commit 70d2c91

File tree

5 files changed

+64
-18
lines changed

5 files changed

+64
-18
lines changed

Amnahjava/src/com/java/basics/objExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
package com.java.basics;
24

35
/* Name of the class has to be "Main" only if the class is public. */
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.objexample.encapsulation;
2+
3+
import java.util.Scanner;
4+
5+
class LinearSearch {
6+
public static void main(String[] args) {
7+
int counter, num, item, array[];
8+
Scanner inputValue = new Scanner(System.in);
9+
System.out.println("enter the elements");
10+
num = inputValue.nextInt();
11+
array = new int[num];
12+
System.out.println("enter" + num + "integers");
13+
for (counter = 0; counter < num; counter++)
14+
array[counter] = inputValue.nextInt();
15+
System.out.println("enter the search valur");
16+
item = inputValue.nextInt();
17+
inputValue.close();
18+
for (counter = 0; counter < num; counter++) {
19+
if (array[counter] == item) {
20+
System.out.println(item + " is present at location " + (counter + 1));
21+
break;
22+
}
23+
}
24+
if (counter == num)
25+
System.out.println(item + " doesn't exist in array.");
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.objexample.encapsulation;
2+
3+
public class Pattern {
4+
public static void main(String[] args) {
5+
int i, j;
6+
for (i = 1; i <= 5; i++) {
7+
for (j = 1; j <= i; j++)
8+
System.out.print(j);
9+
System.out.println();
10+
}
11+
12+
}
13+
}
Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package com.objexample.encapsulation;
2+
23
import java.util.Scanner;
34

45
public class UserInput {
56
public static void main(String[] args) {
6-
Scanner sc= new Scanner(System.in);
7+
Scanner sc = new Scanner(System.in);
78
System.out.println("enter your total bill");
8-
int bill=sc.nextInt();
9-
System.out.println("enter your discount");
10-
double Discount=sc.nextDouble();
11-
System.out.println("your discount is" + Discount);
12-
//double vat= discount*(5.5/100);
13-
//System.out.println("your vat is" + vat);
14-
//double Vat=sc.nextDouble();
15-
double Newbill= bill*(10/100);
16-
System.out.println("your new bill is" + Newbill);
9+
int bill = sc.nextInt();
10+
System.out.println("enter your discount in %");
11+
double discount = sc.nextDouble();
12+
System.out.println("enter your Vat");
13+
double vat = sc.nextDouble();
14+
double discountc = bill * (discount / 100);
15+
double vatc = bill * (vat / 100);
16+
double netbill = bill - discountc;
17+
System.out.println("your Total bill is " + bill);
18+
System.out.println("your vat is " + vatc);
19+
System.out.println("your discount is " + discountc);
20+
System.out.println("your Net Amount is " + netbill);
1721
sc.close();
18-
22+
1923
}
2024

2125
}
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package com.objexample.encapsulation;
22

33
public class series {
4-
public static void main(String[] args) {
5-
int i;
6-
for(i=1;i<=10;i++){
7-
System.out.print(2*i);
8-
// for(i=1;i<=10;i++)
9-
System.out.print(3*i);}
10-
}
4+
public static void main(String[] args) {
5+
int i;
6+
for (i = 1; i <= 10; i++) {
7+
System.out.print(i * 2);
8+
System.out.print(3 * i);
9+
}
10+
}
1111
}

0 commit comments

Comments
 (0)