Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions 10Inputs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package pack1;

import java.util.Scanner;


public class UserIO {

public static void main(String[] args){

Scanner scan = new Scanner(System.in);

int user_input;
int odds=0;
int evens;
String evenList="";
String oddList="";


for(int i=0; i<10; i++)
{
System.out.println("Enter a number");
user_input = Scan.nextInt();

if(user_input%2>0)
{

odds+=user_input;
oddList+=user_input+" ";

}



else
{
evens+=user_input;
evenList+=user_input+" ";

}

System.out.Println("The Sum of Odd Numbers= "+odds);
System.out.Println("The Sum of Even Numbers= "+evens);
System.out.Println("The List of Odd Numbers= "+oddList);
System.out.Println("The List of Even Numbers= "+evenList);

}



}

}
68 changes: 68 additions & 0 deletions ListInsteadOfFor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package pack1;

import java.util.Random;

public class Arrays {


public static void list(int[] array, int length){

for(int i=0; i<5;i++)
{
System.out.print(array[i]+" ");
}
System.out.println();
}

public static void main(String[] args)
{
/*int[] array1=new int[5];
int[] array2={3,5,7,8,2};

int length=array1.length; //Gives length of array assign to length*/

int[] array1=new int[5];
int[] array2=new int[5];
int[] result=new int[5];

Random rnd=new Random();

for(int i=0;i<5;i++)
{

array1[i]=rnd.nextInt(11)+10;
array2[i]=rnd.nextInt(11)+10;
result[i]=array1[i]+array2[i];

}


list(array1,array1.length);
list(array2,array2.length); //İnstead of below for
list(result,result.length);

/*for(int i=0; i<5;i++)
{
System.out.print(array1[i]+" ");
}
System.out.println();
for(int i=0; i<5;i++)
{
System.out.print(array1[i]+" ");
}
System.out.println();

for(int i=0; i<5;i++)
{
System.out.print(array2[i]+" ");
}
System.out.println();

for(int i=0; i<5;i++)
{
System.out.print(result[i]+" ");
}*/

}

}