Java Programming
Java Programming
Java Programming
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
System.out.print("Enter x: ");
int x = sc.nextInt();
System.out.print("Enter y: ");
int y = sc.nextInt();
System.out.print("Enter z: ");
int z = sc.nextInt();
System.out.print("Sum: "+ (x+y+z));
}
}
FAHRENHEIT TO CELSIUS
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
System.out.print("Enter tempereture in Fahrenheiht: ");
double f = sc.nextDouble();
System.out.printf("Temperature in Celsius: %.2f", ((f-32)*5/9));
}
}
REWARD MONEY
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
System.out.print("Enter the reward money: ");
int m = sc.nextInt();
if(m<100){
System.out.print("That's too low");
} else if (m>1000){
System.out.print("That's too much");
}else
System.out.print("That's enough");
}
}
COUNTDOWN WITH A FOR LOOP
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
NUMBER TRIANGLE
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
}
public static void printDecendingNumbers(int n){
for(int i = p; i>=0; i--){
System.out.println(i);
}
}
}
ENCAPSULATION PRACTICE I
import java.util.*;
public class Basta{
private String name;
private int year;
private String publisher;
public void setter(){
Scanner sc = new Scanner(System.in);
System.out.print("Enter game name: ");
this.name = sc.nextLine();
System.out.print("Enter year published: ");
this.year = sc.nextInt();
sc.nextLine();
System.out.print("Enter game publisher: ");
this.publisher = sc.nextLine();
}
public String getName(){
return name;
}
public int getYear(){
return year;
}
public String getPublisher(){
return publisher;
}
}
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
}
}
INHERITANCE PRACTICE I
import java.util.*;
public class Main{
public static void main (String[] args){
Scanner sc = new Scanner (System.in);
student.setter();
student.displayDetails();
}
}
import java.util.*;
public class Student extends Person{
String school;
int id;
int yearStarted;
import java.util.*;
}
ARRAY TRANSVERSAL QUIZ
import java.util.Scanner;
import java.text.DecimalFormat;
public class ArraySumAndAverage {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
DecimalFormat dc= new DecimalFormat("###.00");
}
}
public interface Polygon{
public double area(double base, double height);
}
System.out.print("Enter x: ");
int x= sc.nextInt();
System.out.print("Enter y: ");
int y= sc.nextInt();
try{
int answer =x/y;
System.out.println("Qoutient: "+ answer);
}catch(ArithmeticException e){
System.out.print("Division by zero is illegal");
}
}
}