Professional Documents
Culture Documents
CSC 2513 - Udit Kumar Mahato
CSC 2513 - Udit Kumar Mahato
CSC 2513 - Udit Kumar Mahato
class While {
public static void main(String[] args) {
// declare variables
int i = 1, n = 5;
import java.util.Scanner;
class DoWhile {
public static void main(String[] args) {
int i = 1, n = 5;
Code:
//compare two numbers
import java.util.Scanner;
public class CheckGreaterSmaller {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//to take first num
System.out.print("Enter the first number : ");
int firstNum=input.nextInt();
//to take second num
System.out.print("Enter the second number : ");
int SecondNum=input.nextInt();
//If else statement to compare the two numbers
if(SecondNum>firstNum){
System.out.println(SecondNum+" is greater than "+firstNum);
}
else{
System.out.println(firstNum+" is greater than "+SecondNum);
}
}
}
Output:
Code:
import java.util.Scanner;
//Main class created
public class TakeInputString {
public static void main(String[ ] arg)
{
//Created boolean statement
boolean isVowel=false;;
Scanner scanner=new Scanner(System.in);
//To take input from user
System.out.print("Enter a string with length more than 2 : ");
String Word=scanner.next();
//Convert String to Lowercase
String Converted=Word.toLowerCase();
//To know the letter that is second character of the given string
char index = Converted.charAt(1);
//Closed Scanner
scanner.close();
//loop to decide either the second character is vowel or Constant
switch(index)
{
case 'a' :
case 'e' :
case 'i' :
case 'o' :
case 'u' :
case 'A' :
case 'E' :
case 'I' :
case 'O' :
case 'U' : isVowel = true;
}
if(isVowel == true) {
System.out.println(index +" is a Vowel");
}
else {
if((index >='a'&&index <='z')||(index>='A'&&index <='Z'))
System.out.println(index +" is a Consonant");
else
System.out.println("Input is not an alphabet");
}
}
}
Output:
}
System.out.println("\n\n More Purchases(y/n)?");
ex = sc.next().charAt(0);
} while (ex == 'y');
if(TotalPurchase<=100.99 && TotalPurchase>0){
discount=0.05*TotalPurchase;
}
else if(TotalPurchase<=200.99){
discount=0.08*TotalPurchase;
}
else if(TotalPurchase>201){
discount=0.10*TotalPurchase;
}
else{
System.out.println("Wrong Amount");
}
payableAmt=TotalPurchase-discount;
Scanner n=new Scanner(System.in);
System.out.print("Enter customer name for billing: ");
String name=n.nextLine();
out.printf("\n"+"Customer Name : "+name);
out.printf("\n"+"Total purchase amount(Rs.) "+TotalPurchase);
out.printf("\n"+"Discount Amount(Rs.) "+discount);
out.printf("\n"+"Amount payable after discount(Rs. ) "+payableAmt);
sc.close();
n.close();
out.close();
}
}
Output:
Textfile:
Code:
//bank services java program
import java.util.Scanner;
public class Bank {
String Customer_name;
double balance;
//Created constructor named bank
Bank(String name){
Customer_name = name;
balance = 1000;
}
//Method for deposit
public void deposit(double depositamt){
balance+=depositamt;
}
//method to withdraw
public void withdraw(double withdrawamt){
if (withdrawamt>balance){
System.out.println("Sufficient Balance");
}
else {
balance -= withdrawamt;
System.out.println(withdrawamt + " successfully withdrawn");
}
}
//Method to checkBalance
public void checkBalance(){
System.out.println("Balance: " + balance);
}
//method to print customer name and available balance
public void display(){
System.out.println("\nName: " + Customer_name);
System.out.println("Amount Available: Rs. " + balance);
}
//Main method
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Bank b1 = new Bank("Sunway College");
b1.display();
System.out.print("\nEnter deposit amount: Rs. " );
double deposit = sc.nextDouble();
b1.deposit(deposit);
System.out.println(deposit+" successfully deposited");
System.out.print("\nEnter withdraw amount: Rs. ");
double withdraw = sc.nextDouble();
b1.withdraw(withdraw);
b1.display();
}
}
Output: