java-1 2
java-1 2
System.out.println("Hello\r world\n");
}
Write a program to convert temperature from Celsius to Fahrenheit by
import java.util.Scanner;
class DegFaren {
float d = sc.nextFloat();
}
Write a program to accept values in different data types, try to assign int to
double, int to byte, and vice versa. Demonstrate the use of Implicit
import java.util.Scanner;
sc.close();
}
}
Write a program to check whether the person’s age allows him to cast the
vote or not
import java.util.Scanner;
} else {
scanner.close();
}
Write a program to check whether the person’s age and citizenship allows
import java.util.Scanner;
System.out.println("You are not eligible to vote because you are under 18.");
} else {
System.out.println("You are not eligible to vote because you are not a citizen.");
scanner.close();
}
Write a program to find the greatest number among the 3 numbers given by
the user.
import java.util.Scanner;
double greatest;
greatest = num1;
greatest = num2;
} else {
greatest = num3;
scanner.close();
}
Write a program to check if a given number is a prime number or not.
import java.util.Scanner;
if (num <= 1) {
} else {
if (num % i == 0) {
isPrime = false;
break;
}}
if (isPrime) {
} else {
}}
scanner.close();
}
Write a program to design a Food/ Restaurant Management System using
import java.util.Scanner;
System.out.println("1. Starters");
System.out.println("3. Desserts");
System.out.println("4. Drinks");
double totalBill = 0;
if (categoryChoice == 1) {
System.out.println("Choose a starter:");
if (starterChoice == 1) {
totalBill += 5;
} else if (starterChoice == 2) {
totalBill += 7;
} else if (starterChoice == 3) {
totalBill += 4;
} else {
} else if (categoryChoice == 2) {
if (mainCourseChoice == 1) {
totalBill += 10;
} else if (mainCourseChoice == 2) {
totalBill += 8;
} else if (mainCourseChoice == 3) {
totalBill += 9;
} else {
} else if (categoryChoice == 3) {
System.out.println("Choose a dessert:");
if (dessertChoice == 1) {
totalBill += 3;
} else if (dessertChoice == 2) {
totalBill += 4;
} else if (dessertChoice == 3) {
totalBill += 5;
} else {
} else if (categoryChoice == 4) {
System.out.println("Choose a drink:");
if (drinkChoice == 1) {
totalBill += 1;
} else if (drinkChoice == 2) {
totalBill += 2;
} else if (drinkChoice == 3) {
totalBill += 3;
} else {
} else {
scanner.close();
}
Write a program to make a calculator (+,-, *,/,%) depicting all arithmetic
operators
import java.util.Scanner;
double result = 0;
if (operator == '+') {
if (num2 != 0) {
} else {
return;
}
} else if (operator == '%') {
} else {
System.out.println("Invalid operator!");
return;
System.out.println("Result: " + num1 + " " + operator + " " + num2 + " = " + result);
scanner.close();
}
Write a program using bitwise operator (&,|,^,~, >>, <<, >>>)
import java.util.Scanner;
scanner.close();
}
}
Write a program to execute the loop from 1 to 10 and display output: 1,3,5,9
if (i == 1 || i == 3 || i == 5 || i == 9) {
}
Write a program to execute the loop 10 times from 10 to 1 and display
output: 10,9,8,7,6,5,4,3,2,1
System.out.print(i + ",");
}
Write a program to display the following pattern upto N rows, taking the
12
123
1234
import java.util.Scanner;
int N = scanner.nextInt();
System.out.print(j);
System.out.println();
scanner.close();
}
Write a program to input marks of 50 students using an array and display
import java.util.Scanner;
int totalMarks = 0;
marks[i] = scanner.nextInt();
totalMarks += marks[i];
scanner.close();
}
Write a program to display the following pattern upto
**
***
****
System.out.print("*");
System.out.println();
}
Write a program to display the following pattern
******
***
System.out.print("*");
System.out.println();
}
Write a program where a loop will execute from 1 to 1000 times, but break
after it receives 3
System.out.println(i);
if (i == 3) {
break;