Restore
This commit is contained in:
0
Labs/Lab2/Lab2Part1/.metadata/.lock
Normal file
0
Labs/Lab2/Lab2Part1/.metadata/.lock
Normal file
2976
Labs/Lab2/Lab2Part1/.metadata/.log
Normal file
2976
Labs/Lab2/Lab2Part1/.metadata/.log
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
||||
|
||||
public class CheckOddEven {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
public class PrintNumberInWord {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int number = 9;
|
||||
|
||||
if(number < 0 || number > 9) {
|
||||
System.out.println("OTHER");
|
||||
}
|
||||
else {
|
||||
if(number == 1) System.out.println("ONE");
|
||||
if(number == 2) System.out.println("TWO");
|
||||
if(number == 3) System.out.println("THREE");
|
||||
if(number == 4) System.out.println("FOUR");
|
||||
if(number == 5) System.out.println("FIVE");
|
||||
if(number == 6) System.out.println("SIX");
|
||||
if(number == 7) System.out.println("SEVEN");
|
||||
if(number == 8) System.out.println("EIGHT");
|
||||
if(number == 9) System.out.println("NINE");
|
||||
}
|
||||
|
||||
switch(number) {
|
||||
case 1:System.out.println("ONE");
|
||||
break;
|
||||
case 2:System.out.println("TWO");
|
||||
break;
|
||||
case 3:System.out.println("THREE");
|
||||
break;
|
||||
case 4:System.out.println("FOUR");
|
||||
break;
|
||||
case 5:System.out.println("FIVE");
|
||||
break;
|
||||
case 6:System.out.println("SIX");
|
||||
break;
|
||||
case 7:System.out.println("SEVEN");
|
||||
break;
|
||||
case 8:System.out.println("EIGHT");
|
||||
break;
|
||||
case 9:System.out.println("NINE");
|
||||
break;
|
||||
default:System.out.println("OTHER");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
for(int i = 0; i < str.length()/2; i++) {
|
||||
if(str.charAt(i) != str.charAt(str.length()-i)) {
|
||||
System.out.println("The word is not a palindrome.");
|
||||
}
|
||||
}
|
||||
System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.nextLine();
|
||||
String res = "";
|
||||
for(int i = str.length() - 1; i >= 0; i--) {
|
||||
res = res + str.charAt(i);
|
||||
}
|
||||
System.out.println("The reverse of the string "" " + str + " is " + res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
float meter = 0.0254f * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
}
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254f;
|
||||
System.out.printf(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 1; i <= numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1, flag = 0;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
flag++;
|
||||
break;
|
||||
}
|
||||
begin++;
|
||||
end--;
|
||||
}
|
||||
System.out.println((flag == 1) ? ("The word is not a palindrome.") : ("The word is a palindrome."));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
public class CheckOddEven {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int num = 49;
|
||||
System.out.println("The number is " + num);
|
||||
if(num % 2 == 0) System.out.println("Odd number");
|
||||
else System.out.println("Even number");
|
||||
System.out.println("BYE!");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CheckPassFail {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int mark = 50;
|
||||
System.out.print("The mark is " + mark);
|
||||
if(mark >= 50) System.out.println("PASS");
|
||||
else System.out.println("FAIL");
|
||||
System.out.println("DONE");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudents = new int[numStudents];
|
||||
System.out.print("Enter the grade for students: ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
int i = 1;
|
||||
do{
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
while(i <= 100);
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + (float)sum/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
float meter = 0.0254 * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CheckPassFail {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Input a mark: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
int mark = input.nextInt();
|
||||
if(mark >= 50) System.out.println("PASS");
|
||||
else System.out.println("FAIL");
|
||||
}
|
||||
System.out.println("DONE");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254f * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.printfln("Input an integer between 0 and 1000: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
int num = input.nextInt();
|
||||
int sum = 0;
|
||||
for(int i = 0; i < sizeof(num); ++i) {
|
||||
sum += num[i];
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
int i = 1;
|
||||
while(i <= 100) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + (float)sum/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class CheckPassFail {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input an integer between 0 and 1000: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
int int_3 = input.nextInt();
|
||||
int digitSum = 0;
|
||||
int divisor = int_3;
|
||||
while(divisor > 0) {
|
||||
digitSum += divisor % 10;
|
||||
divisor /= 10;
|
||||
}
|
||||
System.out.println("The sum of all digits in " + int_3 + " is " +digitSum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String origin = input.nextLine();
|
||||
String revers = origin;
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
revers.charAt(i) = revers.charAt(revers.length()-i);
|
||||
}
|
||||
System.out.println("The reverse of the string " + origin + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 0; i < numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i+1 + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
}
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254;
|
||||
System.out.println("%lf",meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254f;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.nextLine();
|
||||
String res = "";
|
||||
for(int i = str.length() - 1; i >= 0; i--) {
|
||||
res = res + str.charAt(i);
|
||||
}
|
||||
System.out.println("The reverse of the string " + str + " is " + res);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 0; i < numStudents; i++) {
|
||||
int cnt = i + 1;
|
||||
System.out.print("Enter the grade for student " + cnt + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String origin = input.nextLine();
|
||||
String revers = input.nextLine();
|
||||
for(int i = 0; i < (int)revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
}
|
||||
System.out.println("The reverse of the string " + origin + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(inch + "inches is" + meter + "meters");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 0; i < numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i+1 + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class PrintNumberInWord {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in) {
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
float ave;
|
||||
for(int i = 1; i <= 100; i++) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out println("The average is " + ave/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
(Scanner input = new Scanner(System.in);){
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class CheckPassFail {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int mark = 50;
|
||||
System.out.println("The mark is " + mark);
|
||||
if(mark >= 50) System.out.println("PASS");
|
||||
else System.out.println("FAIL");
|
||||
System.out.println("DONE");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input an integer between 0 and 1000: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
int num = input.nextInt();
|
||||
int sum = 0;
|
||||
for(int i = 0; i < sizeof(num); ++i) {
|
||||
sum += num[i];
|
||||
}
|
||||
System.out.println(sum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
float ave;
|
||||
for(int i = 1; i <= 100; i++) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + ave/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
System.out.println("The word is not a palindrome.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
for(int i = 1; i <= 100; i++) {
|
||||
sum += i;
|
||||
}
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + (float)sum/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
try (Scanner input = new Scanner(System.in)) {
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(inch + " inches is " + meter + " meters ");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
int i = 1;
|
||||
do{
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
while(i <= 100)
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + (float)sum/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input an integer between 0 and 1000: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
int int_3 = input.nextInt();
|
||||
int digitSum = 0;
|
||||
int divisor = int_3;
|
||||
while(divisor > 0) {
|
||||
digitSum += divisor % 10;
|
||||
divisor /= 10;
|
||||
}
|
||||
System.out.println(digitSum);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1, flag = 0;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
flag++;
|
||||
break;
|
||||
}
|
||||
begin++, end--;
|
||||
}
|
||||
if(flag == 1) System.out.println("The word is not a palindrome.");
|
||||
else System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
System.out.println("The word is not a palindrome.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
public class SumAndAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int sum = 0;
|
||||
int i = 1;
|
||||
while(i <= 100) {
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
System.out.println("The sum is " + sum);
|
||||
System.out.println("The average is " + (float)sum/100);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254;
|
||||
System.out.printf("%lf",meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String origin = input.nextLine();
|
||||
String revers = input.nextLine();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
}
|
||||
System.out.println("The reverse of the string " + origin + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1, flag = 0;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
flag++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag == 1) System.out.println("The word is not a palindrome.");
|
||||
else System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 1; i <= numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.nextLine();
|
||||
String res = "";
|
||||
for(int i = str.length() - 1; i >= 0; i--) {
|
||||
res = res + str.charAt(i);
|
||||
}
|
||||
System.out.println("The reverse of the string \" " + str + " \" is \" " + res + " \"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 1; i <= numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i + " : ");
|
||||
gradeStudent[i] = input.nextInt();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254;
|
||||
System.out.println(meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
for(int i = 0; i < str.length()/2; i++) {
|
||||
if(str.charAt(i) != str.charAt(str.length()-i)) {
|
||||
System.out.println("The word is not a palindrome.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class TestPalindrome {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Please input a word: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String str = input.next();
|
||||
str = str.toLowerCase();
|
||||
int begin = 0, end = str.length()-1, flag = 0;
|
||||
while(begin != end) {
|
||||
if(str.charAt(begin) != str.charAt(end)) {
|
||||
flag++;
|
||||
break;
|
||||
}
|
||||
begin++;
|
||||
end--;
|
||||
}
|
||||
if(flag == 1) System.out.println("The word is not a palindrome.");
|
||||
else System.out.println("The word is a palindrome.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = 0.0254 * inch;
|
||||
System.out.println(inch + " inches is " + meter + " meters ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < (int)revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
revers.replace(begin, end);
|
||||
revers.replace(end, begin);
|
||||
}
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
}
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class SumOfDigits {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GradesAverage {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the number of students: ");
|
||||
int numStudents = input.nextInt();
|
||||
int[] gradeStudent = new int[numStudents];
|
||||
int sum = 0;
|
||||
for(int i = 1; i <= numStudents; i++) {
|
||||
System.out.print("Enter the grade for student " + i + " : ");
|
||||
gradeStudent[i] = input.next();
|
||||
if(gradeStudent[i] < 0 || gradeStudent[i] > 100) {
|
||||
System.out.println("Invalid grade, try again...");
|
||||
--i;
|
||||
continue;
|
||||
}
|
||||
sum += gradeStudent[i];
|
||||
}
|
||||
System.out.println("The average is : " + sum/numStudents);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("hello");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InchesToMeters {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
System.out.println("Input a value for inches: ");
|
||||
Scanner input = new Scanner(System.in);
|
||||
double inch = input.nextDouble();
|
||||
double meter = inch/0.0254f;
|
||||
System.out.printf("%lf",meter);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class ReverseString {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.print("Enter a string: ");
|
||||
try(Scanner input = new Scanner(System.in)){
|
||||
String revers = input.next();
|
||||
for(int i = 0; i < revers.length()/2; i++) {
|
||||
char begin = revers.charAt(i);
|
||||
char end = revers.charAt(revers.length()-i);
|
||||
System.out.println("The reverse of the string " + " is " + revers);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user