This repository has been archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
478 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.util.Scanner; | ||
public class Array01{ | ||
public static void main(String [] args){ | ||
Scanner sc = new Scanner(System.in); | ||
|
||
int i, num ; | ||
System.out.print("Enter Length of Array: "); | ||
num = sc.nextInt(); | ||
|
||
int [] arr = new int[num]; | ||
System.out.println("Enter " + num + " Elements: "); | ||
for (i = 0; i <num;i++){ | ||
arr[i] = sc.nextInt(); | ||
} | ||
System.out.println("Elements in Array"); | ||
for(i = 0; i<num; i++){ | ||
System.out.print(arr[i] + "\t"); | ||
} | ||
int sum = 0; | ||
for(i = 0; i<num; i++){ | ||
sum += arr[i]; | ||
} | ||
System.out.println("\r\rSum is: " + sum); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
import java.util.Collections; | ||
public class Array02{ | ||
public static void main(String [] args){ | ||
Scanner sc = new Scanner(System.in); | ||
|
||
int i, num; | ||
System.out.print("Enter length of array: "); | ||
num = sc.nextInt(); | ||
|
||
int[] arr1 = new int[num]; | ||
int[] arr2 = new int[num]; | ||
System.out.println("Enter " + num + " elements: "); | ||
for (i = 0; i < num; i++){ | ||
arr1[i] = sc.nextInt(); | ||
} | ||
|
||
Arrays.sort(arr1); | ||
System.out.println("\rElements of array2 are: " + Arrays.toString(arr1)); | ||
|
||
Collections.reverse (Arrays.asList(arr1)); | ||
System.out.println("\rElements of array2 are: " + Arrays.toString(arr1)); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
public class Array03{ | ||
public static void main(String [] args){ | ||
Scanner sc = new Scanner(System.in); | ||
int i, num; | ||
System.out.print("Enter length of array: "); | ||
num = sc.nextInt(); | ||
|
||
int[] arr = new int[num]; | ||
System.out.println("Enter " + num + " elements: "); | ||
for(i = 0; i<num; i++){ | ||
arr[i] = sc.nextInt(); | ||
} | ||
Arrays.sort(arr); | ||
System.out.print(Arrays.toString(arr)); | ||
|
||
int sum = 0; | ||
for(i = 0; i < num; i++){ | ||
sum += arr[i]; | ||
} | ||
System.out.println("Sum is: " + sum); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
public class Array1{ | ||
public static void main(String [] args){ | ||
double prices[] = {12.43,13.42,13.23,15.00,25.00}; | ||
for (int i=0; i < prices.length; i++){ | ||
System.out.println(prices[i]); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import java.util.Scanner; | ||
public class Binary1{ | ||
public static void main(String args []){ | ||
int n; | ||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.print("Enter any number: "); | ||
n = sc.nextInt(); | ||
System.out.println("Binary number: " + Integer.toBinaryString(n)); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
*Scanner dahil static na program | ||
*or with user input. | ||
*Reminders: | ||
*This may or may totally not be | ||
*included sa activity tomorrow | ||
*Thank you <3 | ||
*/ | ||
|
||
import java.util.Scanner; | ||
public class Conditions1 { | ||
public static void main (String [] args){ | ||
Scanner sc = new Scanner(System.in); | ||
double no; //no is number | ||
|
||
System.out.print("Input your grade: "); | ||
no = sc.nextDouble(); | ||
|
||
if (no >= 90){ | ||
System.out.print("A"); | ||
} else if (no >= 80){ | ||
System.out.print("B"); | ||
} else if (no >= 75){ | ||
System.out.print("C"); | ||
} else if (no < 50 || no > 100){ | ||
System.out.print("Input Error"); | ||
} else { | ||
System.out.print("F"); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* Data Type Conversion | ||
*/ | ||
public class Conversion { | ||
public static void main(String[] args) { | ||
|
||
//variable x is float data type | ||
float x = 2.89f; | ||
//variable y is an integer data type | ||
int y = (int) x; | ||
//float x will be convert to integer | ||
System.out.println("Float to Int: " + y); | ||
//displays y into integer | ||
//output should be 2 | ||
|
||
} | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
public class Conversion1 { | ||
public static void main (String[] args){ | ||
final int grade = 80; | ||
final int size = 20; | ||
double final_grade = (double) grade; | ||
double final_size = (double) size; | ||
|
||
//Displays final size and final grade variables | ||
System.out.println(final_grade); | ||
System.out.println(final_size); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
public class Conversion2 { | ||
public static void main (String[]main) { | ||
String str = "1050"; | ||
|
||
int inum = Integer.parseInt(str); | ||
System.out.println(inum); | ||
|
||
int onum = Integer.valueOf(str); | ||
System.out.println(onum); | ||
} | ||
} |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import java.util.*; | ||
public class Exception01{ | ||
public static void main(String [] args){ | ||
Exception01 ex = new Exception01(); | ||
ex.input(); | ||
} | ||
public void input(){ | ||
Scanner sc = new Scanner(System.in); | ||
int dividend, divisor, quotient; | ||
System.out.print("Enter dividend: "); | ||
dividend = sc.nextInt(); | ||
System.out.print("Enter divisor: "); | ||
divisor = sc.nextInt(); | ||
try{ | ||
quotient = dividend / divisor; | ||
System.out.print(dividend + " / " + divisor + " = " + quotient); | ||
} | ||
catch(ArithmeticException e){ | ||
System.out.println("Divisor cannot be 0"); | ||
System.out.println("Try again."); | ||
} | ||
catch(InputMismatchException e){ | ||
System.out.print("Wrong data type!"); | ||
System.out.println("Try again."); | ||
} | ||
finally{ | ||
System.out.println("\rThank you!"); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import java.util.Scanner; | ||
public class ForLoop1 { | ||
public static void main (String [] args){ | ||
|
||
Scanner sc = new Scanner(System.in); | ||
int num; | ||
|
||
System.out.print("Enter a positive number: "); | ||
num = sc.nextInt(); | ||
|
||
for (int i = 1; i<=10; i++){ | ||
System.out.println(num + " x " + i + " = " + (num*i) ); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import java.util.Scanner; | ||
public class ForLoop2 { | ||
public static void main(String [] args){ | ||
int base, power; | ||
int result = 1; | ||
|
||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.print("Enter the base number: "); | ||
base = sc.nextInt(); | ||
|
||
System.out.print("Enter the power number: "); | ||
power = sc.nextInt(); | ||
|
||
for(int i = 1; i<= power; i++){ | ||
result *= base; | ||
} | ||
System.out.println("Result: " + result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Hello | ||
*/ | ||
public class Hello { | ||
//main method | ||
public static void main(String[] args) { | ||
//Variable x is a string | ||
String x = "Hello Arvin"; | ||
//Says Hello Arvin | ||
System.out.println(x); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.util.Scanner; | ||
public class Measurements{ | ||
public static void main(String [] args){ | ||
Scanner sc = new Scanner(System.in); | ||
double num; | ||
double cm = 0; | ||
String measurement = ""; | ||
String converter = ""; | ||
|
||
System.out.println("Available measurements are: millimeter (mm), centimeter (cm)"); | ||
System.out.print("Enter a measurement: "); | ||
measurement = measurement.toLowerCase(); | ||
measurement = sc.nextLine(); | ||
|
||
System.out.print("Enter a number: "); | ||
num = sc.nextDouble(); | ||
|
||
if(measurement.equals("mm")|| measurement.equals("millimeter")){ | ||
|
||
System.out.println("Available conversion to: centimeter (cm)"); | ||
System.out.print("Convert number to: "); | ||
converter = converter.toLowerCase(); | ||
converter = sc.nextLine(); | ||
|
||
if(converter.equals("cm")||converter.equals("centimeter")){ | ||
cm = num / cm; | ||
System.out.println("Length in centimeter is: " + cm); | ||
} else{ | ||
System.out.println("Error, converter not found."); | ||
} | ||
} else if(measurement.equals("cm")|| measurement.equals("centimeter")){ | ||
System.out.println("test"); | ||
} else { | ||
System.out.print("Error"); | ||
} | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import java.util.Scanner; | ||
public class MyLoopTest { | ||
public static void main(String [] args){ | ||
int sum = 0; | ||
for(int a=0; a<=100; a+=2){ | ||
System.out.println(a); | ||
//sum += a; | ||
} | ||
//System.out.print(sum); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import java.util.Scanner; | ||
class Recursion07{ | ||
public static void reverse(int arr[], int start, int end){ | ||
if(start >= end) | ||
return; | ||
int temp; | ||
temp = arr[start]; | ||
arr[start] = arr[end]; | ||
arr[end] = temp; | ||
|
||
reverse(arr, start+1, end-1); | ||
} | ||
|
||
public static void main(String args[]){ | ||
Scanner sc = new Scanner(System.in); | ||
|
||
System.out.println("Enter Row Array Elements: "); | ||
int n = sc.nextInt(); | ||
|
||
System.out.println("Enter Array Elements: "); | ||
int arr[] = new int[n]; | ||
for(int i = 0; i<n; i++){ | ||
arr[i]=sc.nextInt(); | ||
} | ||
System.out.println("Array Elements: "); | ||
for(int i = 0; i<n; i++){ | ||
System.out.println(arr[i]); | ||
} | ||
|
||
System.out.println("Reversed Array Elements: "); | ||
reverse(arr, 0, n-1); | ||
for(int i = 0; i<n; i++){ | ||
System.out.println(arr[i]); | ||
} | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
public class SampDoWhile{ | ||
public static void main(String [] args){ | ||
int i = 0; | ||
do{ | ||
if (i==0){ | ||
System.out.print("Done"); | ||
} else{ | ||
System.out.print("Oops"); | ||
} | ||
} while(true); | ||
} | ||
} |
Binary file not shown.
Oops, something went wrong.