-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic Java
More file actions
61 lines (60 loc) · 2.03 KB
/
Basic Java
File metadata and controls
61 lines (60 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//1. to convert fahrenheit to celcius
class FahrenheitToCelsius {
public static void main(String[] args) {
int satF;
int sunF;
satF=72;
sunF=78;
double satC=(5D/9)*(satF-32);
double sunC=(5D/9)*(sunF-32);
System.out.println("Weekend Averages");
System.out.println("Saturday: "+satC);
System.out.println("Sunday: "+sunC);
}
}
//2. input from user and convert fahrenheit to celsius
import java.util.Scanner;
class FahrenheitToCelsius {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a Fahrenheit value: ");
int fahrenheit = input.nextInt();
input.nextLine();
double celsius = (5.0/9)*(fahrenheit-32);
System.out.println("Fahrenheit: "+fahrenheit);
System.out.println("Celsius: "+celsius);
if (fahrenheit >= 70)
System.out.println("Yay! A good day to go outside");
}
}
//3. Formatted and Unformatted total (rounds off upto 2 decimals)
import java .util.Scanner;
import java.text.NumberFormat;
public class currency {
public static void main(String[] args) {
int items;
double itemCost, total;
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of items: ");
items = input.nextInt();
System.out.print("Cost per item: ");
itemCost = input.nextDouble();
total = items*itemcost;
System.out.println();
System.out.println("Unformatted Total: " + total);
NumberFormat currencyFormat = NumberFormat.getCurrencyInstance();
System.out.println("Formatted Total: " + currencyFormat.format(total));
}
}
//4. comparison test
public class ComparisonTest {
public static void main(String[] args) {
String x = "hello";
String y = "hell0";
if (x.compareTo(y)>0){
System.out.println("x is greater than y");
System.out.println("x: "+x);
System.out.println("y: "+y);
}
}
}