Skip to content

Commit 040373d

Browse files
committed
Folder
1 parent e1f5a5d commit 040373d

29 files changed

+740
-0
lines changed

AutoCode/Array3Sum.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.Scanner;
2+
3+
public class Array3Sum {
4+
5+
public static void main (String[]args){
6+
7+
Scanner sc = new Scanner (System.in);
8+
9+
System.out.println("Enter size of array");
10+
int n= sc.nextInt(); //arraySize
11+
12+
int a[]= new int[n];
13+
int b[]= new int[n];
14+
int c[]= new int[n];
15+
16+
for (int k=0,i=0;k<n;k++,i++){
17+
18+
System.out.println("Enter "+k+" element for array 'a' : ");
19+
a[k]=sc.nextInt();
20+
System.out.println("Enter "+k+" element for array 'b' : ");
21+
b[k]=sc.nextInt();
22+
c[i]=a[k]+b[k];
23+
}
24+
for (int i=0;i<n;i++){
25+
System.out.println("Sum of elements for both arrays at index "+i+" is "+c[i]);
26+
}
27+
sc.close();
28+
}
29+
}

AutoCode/ArrayArray.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.Scanner;
2+
public class ArrayArray {
3+
public static void main (String[]args) {
4+
Scanner sc = new Scanner(System.in);
5+
System.out.println("Enter percentage of topper : ");
6+
double pT = sc.nextDouble();
7+
String names[]= new String[20];
8+
double marks[]= new double[20];
9+
boolean flag=false;
10+
for (int k=0;k<20;k++){
11+
System.out.println("Enter Name : ");
12+
names[k]=sc.nextLine();
13+
System.out.println("Enter Percentage : ");
14+
marks[k]=sc.nextDouble();
15+
}
16+
for (int i=0;i<20;i++){
17+
if (pT==marks[i] ){
18+
System.out.println("Percentage of topper found ");
19+
System.out.println("Name : "+names[i]);
20+
System.out.println("Percentage : "+marks[i]);
21+
flag=true;
22+
break;
23+
}
24+
}
25+
if (flag==false)
26+
System.out.println("Percentage of topper not found ");
27+
sc.close();
28+
}
29+
}

AutoCode/Arrays.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import java.util.Scanner;
2+
public class Arrays {
3+
public static void main (String[]args){
4+
Scanner sc = new Scanner (System.in);
5+
int a[]= new int[5];
6+
for (int i=0;i<5;i++){
7+
System.out.println("Enter elements : ");
8+
a[i]=sc.nextInt();
9+
}
10+
System.out.println("Elements at odd indexes");
11+
for (int i=0;i<5;i++){
12+
if(i%2!=0)
13+
System.out.println("Element "+a[i]+" is at index "+i);
14+
}
15+
sc.close();
16+
}
17+
}

AutoCode/ArraysProgram.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import java.util.Scanner;
2+
public class ArraysProgram {
3+
public static void main (String[]args){
4+
Scanner sc = new Scanner(System.in);
5+
System.out.println("Enter friend's roll number : ");
6+
int roll = sc.nextInt();
7+
int a[]= new int[20];
8+
boolean flag=false;
9+
10+
for (int k=0;k<20;k++){
11+
12+
System.out.println("Enter roll numbers ");
13+
a[k]=sc.nextInt();
14+
15+
}
16+
for (int k=0;k<20;k++){
17+
if (a[k]==roll){
18+
System.out.println("Roll number found it is at "+(k+1)+" position");
19+
flag=true;
20+
break;
21+
}
22+
}
23+
if(flag==false)
24+
System.out.println("Roll number not found ");
25+
26+
sc.close();
27+
28+
}
29+
}

AutoCode/CollatzConjecture.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
public class CollatzConjecture {
3+
public static void main (String[]args) {
4+
5+
int random_Number=(int)Math.floor(Math.random()*(10000-1+1)+1);
6+
System.out.println(" ");
7+
System.out.println("Random Number : " + random_Number);
8+
System.out.println(" ");
9+
int steps=0;
10+
while (true) {
11+
12+
if (random_Number%2==0) {
13+
random_Number = random_Number/2;
14+
steps++;
15+
}
16+
else if (random_Number%2!=0){
17+
random_Number = (3*random_Number+1);
18+
steps++;
19+
}
20+
System.out.println(random_Number);
21+
22+
if (random_Number==1)
23+
break;
24+
}
25+
System.out.println("Loop");
26+
System.out.println(" ");
27+
System.out.println("Stoppage time = "+steps); // no. of steps
28+
System.out.println(" ");
29+
30+
}
31+
}

AutoCode/EgyptianPyramid.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
public class EgyptianPyramid {
3+
public static void main (String[]args) {
4+
5+
for (int i=1;i<=5;i++){
6+
7+
8+
for(int k=1;k<=5-i;k++){
9+
System.out.print(" ");
10+
}
11+
for(int j=1;j<=i;j++){
12+
System.out.print("* "); // space after asterisk
13+
}
14+
System.out.println();
15+
}
16+
17+
}
18+
}

AutoCode/Function_Overloading.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
public class Function_Overloading {
3+
4+
public static void num_cal(int num, char ch){
5+
if (ch=='s')
6+
System.out.println(num*num);
7+
else
8+
System.out.println(num*num*num);
9+
}
10+
public static void num_cal(int a,int b, char ch){
11+
if (ch=='p')
12+
System.out.println(a*b);
13+
else
14+
System.out.println(a+b);
15+
}
16+
public static void num_cal(char a, char b){
17+
if (a==b)
18+
System.out.println("Same Characters");
19+
else
20+
System.out.println("Different Characters");
21+
}
22+
23+
public static void main (String[]args) {
24+
25+
num_cal(4,'s');
26+
num_cal(5,6,'p');
27+
num_cal('c','c');
28+
29+
}
30+
}

AutoCode/InvertedHalfPyramid.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
public class InvertedHalfPyramid {
3+
4+
public static void main (String[]args) {
5+
6+
for (int i=1;i<=5;i++){
7+
8+
for (int j=1;j<=(6-i);j++){
9+
System.out.print(j);
10+
11+
}
12+
13+
System.out.println();
14+
15+
}
16+
17+
}
18+
}
19+
20+
/*
21+
12345
22+
1234
23+
123
24+
12
25+
1
26+
*/

AutoCode/MaximaMinima.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import java.util.Scanner;
2+
public class MaximaMinima {
3+
4+
static Scanner sc = new Scanner(System.in);
5+
static int count = sc.nextInt();
6+
static int arr [] = new int [count] ;
7+
8+
9+
public static int max(){
10+
int temp ;
11+
for (int i = 0; i < count; i++)
12+
{
13+
for (int j = i + 1; j < count; j++)
14+
{
15+
if (arr[i] > arr[j])
16+
{
17+
temp = arr[i];
18+
arr[i] = arr[j];
19+
arr[j] = temp;
20+
}
21+
}
22+
}
23+
return arr[count-1];
24+
}
25+
26+
27+
28+
public static int min() {
29+
int temp ;
30+
for (int i = 0; i < count; i++)
31+
{
32+
for (int j = i + 1; j < count; j++)
33+
{
34+
if (arr[i] > arr[j])
35+
{
36+
temp = arr[i];
37+
arr[i] = arr[j];
38+
arr[j] = temp;
39+
}
40+
}
41+
}
42+
return arr[0];
43+
}
44+
45+
46+
47+
public static void main (String[]args) {
48+
System.out.println("ENTER ARRAY ELEMENTS ");
49+
for (int i=0;i<count;i++) {
50+
arr[i]=sc.nextInt();
51+
}
52+
53+
System.out.println("MAXIMUM : "+max());
54+
System.out.println("MINIMUM : "+min());
55+
56+
}
57+
58+
}
59+

AutoCode/NumberDecreasingPyramid.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class NumberDecreasingPyramid {
2+
public static void main(String[]args) {
3+
{
4+
int i,j;
5+
for(i=5;i>=1;i--)
6+
{
7+
for(j=i;j>=1;j--)
8+
{
9+
System.out.print(j);
10+
}
11+
System.out.println(" ");
12+
}
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)