FirstFewLessons
This commit is contained in:
106
Basics/src/main/java/com/example/Basics.java
Normal file
106
Basics/src/main/java/com/example/Basics.java
Normal file
@ -0,0 +1,106 @@
|
||||
package com.example;
|
||||
import java.util.Scanner; //We need to importthis class to get text from the command line
|
||||
|
||||
public class Basics {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Write once, run anywhere");
|
||||
System.out.println("Write once, run anywhere!");
|
||||
|
||||
int a = 5;
|
||||
int b = 3;
|
||||
int z = a%b;
|
||||
System.out.println(a-z);
|
||||
|
||||
Scanner sc = new Scanner(System.in); //After importing the Scanner class, we need to create a Scanner object
|
||||
System.out.print("Gimme your name: ");
|
||||
String name = sc.nextLine();
|
||||
|
||||
System.out.print("Gimme your age: ");
|
||||
int age = sc.nextInt();
|
||||
|
||||
System.out.println("Your name is: " + name);
|
||||
System.out.println("Your age is: " + age);
|
||||
|
||||
|
||||
/*
|
||||
Task: Take the bill amount as input and output the corresponding tip amount, which should be 15% of the amount.
|
||||
*/
|
||||
//System.out.print("Gimme the amount: ");
|
||||
System.out.print("Payment: ");
|
||||
if (!(age < 18)) {
|
||||
double amount = sc.nextDouble();
|
||||
System.out.println(amount*15/100);
|
||||
}else{
|
||||
System.out.println("You are not old enaugh to tip!");
|
||||
}
|
||||
|
||||
/*
|
||||
You are making a program for a water sensor that should check if the water is boiling.
|
||||
Take the integer temperature in Celsius as input and output "Boiling" if the temperature is above or equal to 100.
|
||||
Output "Not boiling" if it's not.
|
||||
*/
|
||||
System.out.print("What is the waters temperature? ");
|
||||
int temp = sc.nextInt();
|
||||
if (temp >= 100) {
|
||||
System.out.println("Boiling");
|
||||
}else{
|
||||
System.out.println("Not boiling");
|
||||
}
|
||||
|
||||
if (age < 18) {
|
||||
System.out.print("Give me the number of the day: ");
|
||||
int day = sc.nextInt();
|
||||
switch (day) {
|
||||
case 1:
|
||||
System.out.println("Monday");
|
||||
break;
|
||||
case 2:
|
||||
System.out.println("Tuesday");
|
||||
break;
|
||||
case 3:
|
||||
System.out.println("Wednesday");
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Some Other day, or whatever.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
You are making a robot that should categorize items by their color.
|
||||
Each color corresponds to a box with a specific number.
|
||||
For simplicity, our program will handle 3 colors:
|
||||
red goes to box #1
|
||||
green goes to box #2
|
||||
black goes to box #3
|
||||
|
||||
Your program needs to take a color as input and output the corresponding box number.
|
||||
Sample Input
|
||||
green
|
||||
Sample Output
|
||||
2
|
||||
*/
|
||||
|
||||
System.out.print("Gimme a color: ");
|
||||
Scanner sci = new Scanner(System.in);
|
||||
String color = sci.nextLine();
|
||||
switch (color) {
|
||||
case "red":
|
||||
System.out.println(1);
|
||||
break;
|
||||
case "green":
|
||||
System.out.println(2);
|
||||
break;
|
||||
case "black":
|
||||
System.out.println(3);
|
||||
break;
|
||||
|
||||
default:
|
||||
System.out.println("Something else!");
|
||||
break;
|
||||
}
|
||||
sc.close();
|
||||
sci.close();
|
||||
}
|
||||
}
|
BIN
Basics/target/classes/com/example/Main.class
Normal file
BIN
Basics/target/classes/com/example/Main.class
Normal file
Binary file not shown.
@ -1,14 +0,0 @@
|
||||
package com.example;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Write once, run anywhere");
|
||||
System.out.println("Write once, run anywhere!");
|
||||
|
||||
int a = 5;
|
||||
int b = 3;
|
||||
int z = a%b;
|
||||
System.out.println(a-z);
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
Reference in New Issue
Block a user