Coding in Minutes; Java part 3; Variables and User Input:

Giga Gamby Guide 7 years ago

Açıklama

Results may vary.

Thanks again to Jovan for editing this video!

Have a question? Ask in the comments below!

Code:
package tutorial;
java.util.*;
25:10
public class varsAndInputs {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num, num2, ans;
double deci, deci2;
String statement;

System.out.println("I will add two integers:");
num = scan.nextInt();
num2 = scan.nextInt();
ans = num + num2;

System.out.println(num + " + " + num2 + " = " + ans);
System.out.println(Now I will multiply 2 decimals:");
deci = scan.nextDouble();
deci2 = scan.nextDouble();
System.out.println(deci + " * " + deci2 + " = " + (deci*deci2));

System.out.println("Now I will find the remainder of 2 integers (numerator then denominator):");

num = scan.nextInt()%scan.nextInt();
System.out.println("The remainder is " + num);
31:30
System.out.println("Finally I will put whatever you type into quotations:");
scan.nextLine();
statement = scan.nextLine();
System.out.println("\"" + statement + "\"" + " -me 2018");

}
}

package tutorial;

package tutorial;
import java.util.*;

public class HW2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int length, width, area; //Find the perimeter without a variable representing it!
//Area formula = l*w
//Perimeter formula = 2l + 2w
}
}


package tutorial;

public class HW2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int length, width, area;
System.out.println("Type the length and width of the rectangle, and I'll find the area and perimeter!")
length = scan.nextInt();
width = scan.nextInt();
area = length*weidth
System.out.println("Area = "+ area + "\nPerimeter = " + (2*length + 2*width));
}
}