Skip to content

RAMRAM2502/java.17

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

import java.util.*; public class CoffeeOrder { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String[] drinks = {"Espresso", "Latte", "Cappuccino", "Mocha", "Americano"}; double price = 0; System.out.println("Available drinks:"); for (String d : drinks) System.out.println("- " + d); System.out.print("Enter drink name: "); String drink = sc.nextLine(); System.out.print("Enter size (Small/Medium/Large): "); String size = sc.nextLine().toLowerCase();

switch (size) { case "small": price = 100; break; case "medium": price = 150; break; case "large": price = 200; break; default: System.out.println("Invalid size!"); return; } System.out.print("Add extra shot? (yes/no): "); String extra = sc.nextLine(); if (extra.equalsIgnoreCase("yes")) price += 30;

System.out.println("Total price for " + drink + ": ₹" + price); } }

Problem 2: Arithmetic Operations Using Switch import java.util.*;

public class Calculator { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter first number: "); double a = sc.nextDouble(); System.out.print("Enter second number: "); double b = sc.nextDouble(); System.out.print("Enter operation (+, -, , /): "); char op = sc.next().charAt(0); double result = 0; switch (op) { case '+': result = a + b; break; case '-': result = a - b; break; case '': result = a * b; break; case '/': result = b != 0 ? a / b : 0; break; default: System.out.println("Invalid operation"); return; } System.out.println("Result = " + result); } }

problem 3 Count Characters import java.util.*; class CountCharacters { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter a string: "); String str = sc.nextLine(); int v = 0, c = 0, d = 0, s = 0; str = str.toLowerCase(); for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if ("aeiou".indexOf(ch) != -1) v++; else if (ch >= 'a' && ch <= 'z') c++; else if (ch >= '0' && ch <= '9') d++; else if (ch != ' ') s++; } System.out.println("Vowels=" + v + " Consonants=" + c + " Digits=" + d + " Special=" + s); } }

Problem 4: Bank Interest import java.util.*;

class BankInterest { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); String name = sc.nextLine(); System.out.print("Enter account type (savings/fixed): "); String type = sc.nextLine(); System.out.print("Enter balance: "); double bal = sc.nextDouble(); if (type.equalsIgnoreCase("savings")) bal = bal + (bal * 0.04); else if (type.equalsIgnoreCase("fixed")) bal = bal + (bal * 0.06); System.out.println("Updated balance for " + name + " = ₹" + bal); } }

Problem 5: Temperature Conversion import java.util.*;

class Temperature { public static void main(String args[]) { Scanner sc = new Scanner(System.in); double[] c = new double[5]; System.out.println("Enter 5 temperatures in Celsius:"); for (int i = 0; i < 5; i++) c[i] = sc.nextDouble(); for (int i = 0; i < 5; i++) { double f = (c[i] * 9 / 5) + 32; System.out.println(c[i] + "°C = " + f + "°F"); } } }

Problem 6: Electricity Bill import java.util.*; class ElectricityBill { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter units used: "); int u = sc.nextInt(); double bill = 0; if (u <= 100) bill = u * 1.5; else if (u <= 200) bill = 100 * 1.5 + (u - 100) * 2.5; else bill = 100 * 1.5 + 100 * 2.5 + (u - 200) * 3.5; System.out.println("Total Bill = ₹" + bill); } }

Problem 7: Palindrome Check import java.util.*;

class Palindrome { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter a word: "); String str = sc.nextLine().toLowerCase().replaceAll(" ", ""); String rev = ""; for (int i = str.length() - 1; i >= 0; i--) rev += str.charAt(i); if (str.equals(rev)) System.out.println("Palindrome"); else System.out.println("Not Palindrome"); } }

Problem 8: Replace Characters import java.util.*;

class ReplaceChar { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter a word: "); String word = sc.nextLine().toLowerCase(); String newWord = ""; for (int i = 0; i < word.length(); i++) { char ch = word.charAt(i); switch (ch) { case 'a': newWord += '4'; break; case 'e': newWord += '3'; break; case 'o': newWord += '0'; break; default: newWord += ch; } } System.out.println("Modified word: " + newWord); } }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages