1. Introduction to Salesforce Definition : Salesforce is the #1 Cloud-based CRM (Customer Relationship Management) platform that helps businesses manage relationships with customers, automate business processes, and analyze performance. Founded : 1999 by Marc Benioff. Type : SaaS (Software as a Service). Tagline : "No Software" – because everything runs on the cloud, without local installations. 2. Why Salesforce? Traditional CRMs were expensive and required servers, installations, and IT staff. Salesforce revolutionized CRM by moving everything to the cloud . Benefits: 🚀 Faster implementation ☁️ Cloud-based (accessible anywhere) 🔄 Customizable without coding (point-and-click tools) 🤝 Strong ecosystem & AppExchange (marketplace like Google Play for Salesforce apps) 🔐 Security & scalability 3. Salesforce Products & Cloud Offerings Salesforce is not just CRM; it has multiple clouds (modules) for different busine...
It is used to solve option based program.it provides multiple options using multiple case statements.
If we want to develop a choice based program then we mostly prefer switch statements in Java.
Syntax of Switch:-switch(option)
{
case optionvalue:
statement;
break;
....
default:
statement:
break;
}
at runtime option==optionvalue then that statement will be executed.
case optionvalue:
statement;
break;
....
default:
statement:
break;
}
at runtime option==optionvalue then that statement will be executed.
/* WAP to choose social media platform according to initial char? *
import java.util.Scanner;
class Socialmedia
{
public static void main(String args[])
{
char ch;
Scanner sc = new Scanner(System.in);
System.out.println("Enter you choice of social media to enter initial char");
ch = sc.next().charAt(0);
switch(ch) // ch=='f'
{
case 'f':
case 'F':
System.out.println("You have choosen Facebook");
break;
case 'i':
case 'I':
System.out.println("You have choosen Instagram");
break;
case 't':
case 'T':
System.out.println("You have choosen Twitter");
break;
case 'w':
case 'W':
System.out.println("You have choosen Whatsapp");
break;
default:
System.out.println("Wrong option");
break;
}
}
}
Q) WAP to check vowel and consonant using a switch?
import java.util.Scanner;
class CheckVC
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("enter char");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
System.out.println("Vowel");
break;
default:
System.out.println("Consonent");
break;
}
}
}
int num=5;
switch(num%2)
{
case 0:
System.out.
import java.util.Scanner;
class CheckVC
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("enter char");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
System.out.println("Vowel");
break;
default:
System.out.println("Consonent");
break;
}
}
}
................................................................................................................................................
WAP to check even|odd using switch?int num=5;
switch(num%2)
{
case 0:
System.out.
println("even");
break;
default:
System.out.println("odd");
break;
}
WAP to check the greater number using Switch?
break;
default:
System.out.println("odd");
break;
}
WAP to check the greater number using Switch?
class Greaterswitch
{
public static void main(String args[])
{
int a=10,b=20;
switch(a/b)
{
case 0:
System.out.println("b is greater");
break;
default:
System.out.println("a is greater");
break;
}
}
}.........................................................................................................
2) Nested Switch Statement:-
We can write more than one switch statement using the nested sequence in Java.Nested Switch Statement:-
switch(option)
{
case optionvalue:
switch(option)
{
case optionvalue:
Statement;
break;
default:
Statement;
break;
}
break;
default:
switch(option)
{
case optionvalue:
statement;
break;
default:
statement;
break;
}
break;
}
}
WAP to check divisibility that number is divisible by 3 and 5 both?
import java.util.Scanner;
class CheckVC
{
public static void main(String args[])
{
int num=3;
switch(num%3)
{
case 0:
switch(num%5)
{
case 0:
System.out.println("divisible by both");
break;
default:
System.out.println("only divisible by 3");
break;
}
break;
default:
switch(num%5)
{
case 0:
System.out.println("divisible by five");
break;
default:
System.out.println("not divisible by any");
break;
}
break;
}
}
}
}
WAP to check divisibility that number is divisible by 3 and 5 both?
import java.util.Scanner;
class CheckVC
{
public static void main(String args[])
{
int num=3;
switch(num%3)
{
case 0:
switch(num%5)
{
case 0:
System.out.println("divisible by both");
break;
default:
System.out.println("only divisible by 3");
break;
}
break;
default:
switch(num%5)
{
case 0:
System.out.println("divisible by five");
break;
default:
System.out.println("not divisible by any");
break;
}
break;
}
}
}
.......................................................................................................
WAP to check the greater number using a switch?
The solution to this program:-
class Greater
{
public static void main(String args[])
{
int a=20,b=100;
switch(a/b)
{
case 0:
System.out.println("b is greater");
break;
default:
System.out.println("a is greater");
break;
}
}
}
WAP to check the greatest number using a switch?
class Greater
{
public static void main(String args[])
{
int a=9,b=30,c=7;
switch(a/b)
{
case 0:
switch(b/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("b is greater");
break;
}
break;
default:
switch(a/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("a is greater");
break;
}
break;
}
}
Program to calculate the greatest using the conditional operator?
class SwitchGreater
{
public static void main(String args[])
{
int a=10,b=2000,c=300;
Object o = a>b; //false
switch(o.toString().charAt(0)) //f
{
case 't':
Object o1 = a>c;
switch(o1.toString().charAt(0))
{
case 't':
System.out.println("A is greatest");
break;
default:
System.out.println("C is greatest");
break;
}
break;
default:
Object o2 = b>c; //true
switch(o2.toString().charAt(0)) //t
{
case 't':
System.out.println("b is greatest");
break;
default:
System.out.println("C is greatest");
break;
}
break;
}
}
}
Assignment of Switch:-Q)WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
Q) WAP to check leap year using a switch?
Solution of this program?
import java.util.Scanner;
class CheckLeapYearSwitch
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int year;
System.out.println("Enter year");
year = sc.nextInt();
switch(year%400)
{
case 0:
System.out.println("Leap year");
break;
default:
switch(year%4 )
{
case 0:
switch(year%100)
{
case 0:
System.out.println("Not a leap year");
break;
default:
System.out.println("leap year");
break;
}
break;
default:
System.out.println("Not a leap year");
break;
}
break;
}
}
}
Q) WAP to check entered char is numeric, alphabets, or special using switch?
import java.util.Scanner;
class SwitchExample
{
public static void main(String args[])
{
char ch;
Scanner sc = new Scanner(System.in);
System.out.println("enter char");
ch=sc.next().charAt(0);
Object o=ch>=48 && ch<=57;
Object o1 = ch>=65 && ch<=91 || ch>=97 && ch<=123;
switch(o.toString())
{
case "true":
System.out.println("digit");
break;
default:
switch(o1.toString())
{
case "true":
System.out.println("alphabets");
break;
default:
System.out.println("Special");
}
break;
}
}
}
class Leapyearswitch
ReplyDelete{
public static void main(String args[])
{
int num=2012;
switch(num%4)
{
case 0:
System.out.println("Leap year");
break;
default:
System.out.println("not a leap year");
break;
}
}
}
class Leapyearswitch
ReplyDelete{
public static void main(String args[])
{
int num=2012;
switch(num%4)
{
case 0:
System.out.println("Leap year");
break;
default:
System.out.println("not a leap year");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass evenodd
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
int i=sc.nextInt();
switch(i%2)
{
case 0:
System.out.println("even");
break;
default:
System.out.println("odd");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass CheckVC
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
char x=sc.next().charAt(0);
switch(x)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
System.out.println("Vowel");
break;
default:
System.out.println("consonent value");
}
}
}
import java.util.Scanner;
ReplyDeleteclass Greatnoo
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of a");
int a=sc.nextInt();
System.out.println("enter the value of b");
int b=sc.nextInt();
switch(a/b)
{
case 0:
System.out.println("b is greater than a");
break;
default:
System.out.println("a is greater than b");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass CheckDIV
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
int a=3;
switch(a%3)
{
case 0:
switch(a%5)
{
case 0:
System.out.println("divisible by both");
break;
default:
System.out.println("only div by 3");
break;
}
break;
default:
switch(a%5)
{
case 0:
System.out.println("div by 5");
break;
default:
System.out.println("not div by any");
break;
}
break;
}
}
}
class Greatnoswitch
ReplyDelete{
public static void main(String[]args)
{
int a=9, b=30, c=7;
switch(a/b)
{
case 0:
switch(b/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("b is greater");
break;
}
break;
default:
switch(a/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("a is greater");
break;
}
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass yesnocancle
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
System.out.println("yes");
break;
case 'n':
System.out.println("no");
break;
case 'c':
System.out.println("cancle");
break;
default:
System.out.println("something incorrect");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass leapyear
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the year");
int year=sc.nextInt();
switch(year%4)
{
case 0:
System.out.println("leap year");
break;
default:
System.out.println("this is not a leap year,..");
}
}
}
import java.util.Scanner;
ReplyDeleteclass EO
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter number...");
int num=sc.nextInt();
switch(num%2)
{
case 0:
System.out.println("even");
break;
default:
System.out.println("odd");
break;
}
}
}
// Akshay
ReplyDeleteclass Year
{
public static void main(String args[])
{
int num=2021;
switch(num%4)
{
case 0:
switch(num%100)
{
case 0:
System.out.println("leap");
break;
default:
System.out.println("non leap");
break;
}
break;
default:
switch(400)
{
case 0:
System.out.println("leap");
break;
default:
System.out.println("non leap");
break;
}
break;
}
}
}
import java.util.*;
ReplyDeleteclass Switch
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter char");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'a':System.out.println("vowel");
break;
case 'e':System.out.println("vowel");
break;
case 'i':System.out.println("vowel");
break;
case 'o':System.out.println("vowel");
break;
case 'u':System.out.println("vowel");
break;
default:System.out.println("consonent");
}
}
}
import java.util.*;
ReplyDeleteclass EO
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter number");
int x=sc.nextInt();
switch(x%2)
{
case 0:System.out.println("Even");
break;
default:
System.out.println("odd");
}
}
}
import java.util.*;
ReplyDeleteclass Y
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter ");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'y':System.out.println("yes ");
break;
case 'n': System.out.println("no");
break;
case 'c':System.out.println("cancel");
}
}
}
import java.util.*;
ReplyDeleteclass Leap
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter char");
int x=sc.nextInt();
switch(x%400)
{
case 0:System.out.println("leap year");
switch(x%100!)
{
System.out.println("not leap");
break;
default :
System.out.println("leap year");
}
}
}
}
ReplyDelete/*WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?*/
import java.util.Scanner;
class EnterChoice
{
public static void main(String args[])
{
char ch;
Scanner sc = new Scanner(System.in);
System.out.println("Enter you choice ");
ch = sc.next().charAt(0);
switch(ch)
{
case 'y':
case 'Y':
System.out.println("yes");
break;
case 'n':
case 'N':
System.out.println("no");
break;
case 'c':
case 'C':
System.out.println("cancle");
break;
default:
System.out.println("invalid choice");
break;
}
}
}
import java.util.*;
ReplyDeleteclass LeapYear
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter char");
int num =sc.nextInt();
switch(num%4)
{
case 0:
switch(num%100)
{
case 0:
System.out.println("not leap");
break;
default:
System.out.println(" leap");
break;
}
break;
default:
switch(400)
{
case 0:
System.out.println(" leap");
break;
default:
System.out.println("not leap");
break;
}
break;
}
}
}
ReplyDeleteimport java.util.Scanner;
class EnterPin1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int num = 1000;
int pin =0;
int a = sc.nextInt();
switch(a%num)
{
case 0 :
System.out.println("Enter amount");
break;
default:
System.out.println("1.you eneterd invalid pincode please try Again");
int number = sc.nextInt();
switch(a%num){
case 0 :
System.out.println("Pincode successfully entered");
System.out.println("Enter amount");
int amount = sc.nextInt();
break;
default:
System.out.println("2.you eneterd invalid pincode please try Again");
int b = sc.nextInt();
}
switch(a%num)
{
case 0 :
System.out.println("Pincode successfully entered");
System.out.println("Enter amount");
int amount = sc.nextInt();
break;
default:
System.out.println("3.you eneterd invalid pincode please try Again after 30 min");
}
}
}
}
import java.util.Scanner;
ReplyDeleteclass B_Banking
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int pincode = sc.nextInt();
int i = 1;
int count = 1 ;int balance = 5000 ;
while(i<=pincode)
{
pincode = pincode / 10;
count++;
i++;
}
//System.out.println(count);
switch(count%6)
{
case 0 :
System.out.println("Press C for Credit");
System.out.println("Press D for Debit");
System.out.println("Press B Check Balance");
System.out.println("Press R for Repeat");
System.out.println("Press E for Exit");
char ch = sc.next().charAt(0);
switch(ch)
{
case 'C':
case 'c':
System.out.println("Credit");
System.out.println("Enter Amount");
break;
case 'D':
case 'd':
System.out.println("Debit");
System.out.println("Enter Amount");
break;
case 'B':
case 'b':
System.out.println("Check Balance");
System.out.println("Balance = " +balance);
break;
case 'R':
case 'r':
System.out.println("Repeat");
break;
case 'E':
case 'e':
System.out.println("Exit");
break;
default:
System.out.println("Invalid key");
break;
}
break;
default: System.out.println("Invalid"); break;
}
}
}
//WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
ReplyDeleteimport java.util.Scanner;
class Yesno
{
public static void main(String...args)
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("Enter char");
ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
System.out.println("Yes");
break;
case 'n':
System.out.println("No");
break;
case 'c':
System.out.println("Cancel");
break;
default:
System.out.println("Wrong Choice");
}
}
}
//WAP to check leap year using a switch?
ReplyDeleteimport java.util.Scanner;
class Leap
{
public static void main(String args[])
{
int year, remainder;
Scanner sc=new Scanner(System.in);
System.out.println("Enter Year: ");
year=sc.nextInt();
switch(remainder=(year%4==0)&&((year%400==0)||(year%100!=0)))
{
case 1:
System.out.println("Leap Year.");
break;
case 0:
System.out.println("Not Leap Year.");
break;
default:
System.out.println("Invalid.");
break;
}
}
}
Khushboo Sendre
ReplyDeleteQ)WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
import java.util.Scanner;
class Yesnocancel
{
public static void main(String args[])
{
int ch;
Scanner sc = new Scanner(System.in);
System.out.println("enter the choice");
ch = sc.next().charAt(0);
switch(ch)
{
case'y':
case'Y':
System.out.println(" Your choice is Yes");
break;
case'n':
case'N':
System.out.println("Your choice is No");
break;
case'c':
case'C':
System.out.println("Cancel");
break;
default:
System.out.println("wrong");
break;
}
}
}
Q) WAP to check leap year using a switch?
import java.util.Scanner;
class Leapyear4feb
{
public static void main(String args[])
{
int n;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the year");
n = sc.nextInt();
switch(n%4)
{
case 0:
switch(n%100)
{
case 0:
System.out.println("Year is leap year");
break;
default:
System.out.pritnln("Year is not a leap year");
break;
}
break;
default:
switch(n%400)
{
case 0:
System.out.println("Year is leap year");
break;
default:
System.out.println("Year is not a leap year");
break;
}
break;
}
}
}
// PUSHPENDRA SISODIYA
ReplyDeleteimport java.util.Scanner;
class Switch
{
public static void main(String args[])
{
int num;
Scanner sc=new Scanner(System.in);
System.out.println("enter number");
num=sc.nextInt();
switch(num%2)
{
case 0:
System.out.println("even");
break;
case 1:
System.out.println("odd");
break;
default:
}
}
}
//PUSHPENDRA SISODIYA
ReplyDeleteimport java.util.Scanner;
class Greater
{
public static void main(String args[])
{
int a,b,c,ch;
Scanner sc=new Scanner(System.in);
System.out.println("enter value of a");
a=sc.nextInt();
System.out.println("enter value of b");
b=sc.nextInt();
System.out.println("enter value of c");
c=sc.nextInt();
System.out.println("enter any choice");
ch=sc.nextInt();
switch(ch)
{
case 1:
{
if(a>b)
{
if(a>c)
System.out.println("a is greater");
else
System.out.println("c is greater");
}
else if(b>c)
System.out.println("b is greater");
else
System.out.println("c is greater");
}
break;
default:
}
}
}
ReplyDelete//PUSHPENDRA SISODIYA
import java.util.Scanner;
class Divisible
{
public static void main(String args[])
{
int num;
Scanner sc=new Scanner(System.in);
System.out.println("enter any number");
num=sc.nextInt();
switch(num%3)
{
case 0:
switch(num%5)
{
case 0:
System.out.println("divisible by both");
break;
case 1:
System.out.println("divisible by 3");
}
break;
default:
}
}
}
//PUSHPENDRA SISODIYA
ReplyDeleteimport java.util.Scanner;
class CheckSwitch
{
public static void main(String args[])
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("enter character");
ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
System.out.println("yes");
break;
case 'n':
System.out.println("no");
break;
case 'c':
System.out.println("cancle");
break;
default:
System.out.println("other words");
break;
}
}
}
// Q) WAP to check the greater number using a switch?
ReplyDeleteclass SwitchGreater
{
public static void main(String args[])
{
int a=20,b=10;
switch(a/b)
{
case 0:
System.out.println("b is greater");
break;
default:
System.out.println("a is greater");
break;
}
}
}
//WAP to check divisibility that number is divisible by 3 and 5 both?
ReplyDeleteclass SwitchDivisible
{
public static void main(String[] args) {
int num=31;
switch(num%3)
{
case 0:
switch(num%5)
{
case 0:
System.out.println(num+" is Divisible by 3 and 5");
break;
default:
System.out.println(num+"Divisible by 3 only");
break;
}
break;
default:
switch(num%5)
{
case 0:
System.out.println(num+"is Divisible by 5 only");
break;
default:
System.out.println(num+" is not Divisible by 3 and 5")
break;
}
break;
}
}
}
//Q) WAP to check entered char is numeric, alphabets, or special using switch?
ReplyDeleteimport java.util.Scanner;
class SwitchNumeric
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter Character");
char ch= sc.next().charAt(0);
Object s=(ch>48 && ch<=57);
Object s1=(ch>=64 &&ch<=90)|| (ch>=97 &&ch<=122);
switch(s.toString())
{
case "true":
System.out.println("numeric");
break;
default:
switch(s1.toString())
{
case "true":
System.out.println("characher");
break;
default:
System.out.println("special symbol");
break;
}
break;
}
}
}
// Q) WAP to check the greatest number using a switch?
ReplyDeleteclass SwitchGreatest
{
public static void main(String[] args) {
int a=10,b=50,c=30;
switch(a/b)
{
case 0:
switch(b/c)
{
case 0:
System.out.println("c is gretest");
break;
default:
System.out.println("b is greatest");
break;
}
break;
default:
switch(a/c)
{
case 0:
System.out.println("c is greatest");
break;
default:
System.out.println("a is greatest");
break;
}
break;
}
}
}
//Q)WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
ReplyDeleteclass SwitchYes
{
public static void main(String[] args) {
char ch='h';
switch(ch)
{
case 'Y':
case 'y':
System.out.println("yes");
break;
case 'N':
case 'n':
System.out.println("No");
break;
case 'c':
case 'C':
System.out.println("Cancel");
break;
default:
System.out.println("wrong input");
break;
}
}
}
//Q) WAP to check leap year using a switch?
ReplyDeleteclass SwitchLeap
{
public static void main(String[] args) {
int year=1900;
Object o=(year%4==0 && year%100!=0) ||(year%400==0);
switch(o.toString())
{
case "true":
System.out.println("leap year ");
break;
default:
System.out.println("Not leap year");
break;
}
}
}
WAP to check leap year using a switch
ReplyDeleteProgram:
import java.util.Scanner;
public class LeapYear {
public static void main(String[] args) {
int year;
Scanner scan=new Scanner(System.in);
System.out.print("Enter year- ");
year=scan.nextInt();
switch(year%400) {
case 0:
System.out.print("Leapyear");
break;
default:
switch (year%4) {
case 0:
switch(year%100) {
case 0:
System.out.print("not a Leapyear");
break;
default:
System.out.println(year+" is leap year.");
break;
}
}
}
}
}
WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'
ReplyDeleteProgram:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
char choice;
Scanner scan=new Scanner(System.in);
System.out.print("Enter acharacter (y,n,c)- ");
choice=scan.next().charAt(0);
switch(choice) {
case 'y':
System.out.println("Yes");
break;
case 'n':
System.out.println("No");
break;
case 'c':
System.out.println("Cancel");
break;
default:
System.out.println("Invalid Input!");
}
}
}
//WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
ReplyDeleteimport java.util.Scanner;
class Switchdisplay
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter value");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
System.out.println("yes");
break;
case 'n':
System.out.println("no");
break;
case 'c':
System.out.println("cancel");
break;
default:
System.out.println("try again");
break;
}
}
}
Program to calculate the greatest using the conditional operator?
ReplyDeleteProgram:
import java.util.Scanner;
public class ConditionalOperator {
public static void main(String[] args) {
int a,b,c;
Scanner scan=new Scanner(System.in);
System.out.print("Enter three numbers - ");
a=scan.nextInt();
b=scan.nextInt();
c=scan.nextInt();
Object obj=a>b;
switch(obj.toString().charAt(0)) {
case 't':
Object obj1=a>c;
switch(obj1.toString().charAt(0)) {
case 't':
System.out.println(a+" is greatest");
break;
default:
System.out.println(c+" is greatest");
break;
}
break;
default:
Object obj2=b>c;
switch(obj2.toString().charAt(0)) {
case 't':
System.out.println(b+" is greatest");
break;
default:
System.out.println(c+" is greatest");
break;
}
break;
}
}
}
WAP to check entered char is numeric, alphabets, or special using switch
ReplyDeleteProgram:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
char c;
Scanner scan =new Scanner(System.in);
System.out.print("Enter a character - ");
c=scan.next().charAt(0);
Object obj=(c>=67&&c<=92)||(c>=97&&c<=122);
switch(obj.toString().charAt(0)) {
case 't':
System.out.print(c+" is a alphabet");
break;
default:
Object obj1=(c>=48&&c<=57);
switch(obj1.toString().charAt(0)) {
case 't':
System.out.print(c+" is a digit");
break;
default:
System.out.print(c+" is a special character");
}
}
}
}
// WAP to check leap year using a switch?
ReplyDeleteclass Leap_using_switch
{
public static void main(String abc[])
{
int year=2021;
switch(year%400)
{
case 0:
System.out.println("leap year");
break;
}
switch(year%4)
{
case 0:
switch(year%100)
{
case 0:
System.out.println(" not a leap year");
break ;
default:
System.out.println("leap year");
}
}
}
}
// WAP to check leap year using a switch?
ReplyDeleteclass Leap_using_switch
{
public static void main(String abc[])
{
int year=2021;
switch(year%400)
{
case 0:
System.out.println("leap year");
break;
default:
switch(year%4)
{
case 0:
switch(year%100)
{
case 1:
System.out.println(" leap year");
break ;
}
default:
System.out.println("not a leap year");
}
}
}
}
//WAP to display "yes", "no" and "cancel" when user assign 'y','n', and 'c'?
ReplyDeleteimport java.util.Scanner;
class Displayycn
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter Any Character");
char ch = sc.next().charAt(0);
switch(ch)
{
case'y':
case'Y':
System.out.println("Yes");
break;
case'n':
case'N':
System.out.println("No");
break;
case'c':
case'C':
System.out.println("Cancel");
break;
default:
System.out.println("Invalid input");
}
}
}
ReplyDeleteAnkita Verma
import java.util.Scanner;
class Yesnc
{
public static void main(String args[])
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("Enter your choice");
ch=sc.next().charAt(0);
switch(ch)
{
case'y':
case'Y':
System.out.println("Yes");
break;
case'n':
case'N':
System.out.println("NO");
break;
case'c':
case'C':
System.out.println("Cancel");
break;
default:
System.out.println("Other");
break;
}
}
}
ReplyDeleteAnkita Verma
import java.util.Scanner;
class Leapyear1
{
public static void main(String args[])
{
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter th choice");
n=sc.nextInt();
switch(n%400)
{
case 0:
System.out.println("leap year");
break;
default:
System.out.println(" not leap year");
break;
}
}
}
ReplyDeleteAnkita Verma
import java.util.Scanner;
class Alpha
{
public static void main(String args[])
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("Enter th char");
ch=sc.next().charAt(0);
Object o1=ch>=48 && ch<=57;
Object o2=ch>=65 && ch<=91||ch>=97 && ch<=123;
switch(o1.toString())
{
case"true" :
System.out.println("digit");
break;
default:
switch(o2.toString())
{
case"true":
System.out.println("alphabet");
break;
default:
System.out.println("special");
}
break;
}
}
}
package switchcase;
ReplyDeleteimport java.util.Scanner;
public class Checkyesnocancel {
public static void main(String[] args) {
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("Enter char");
ch=sc.next().charAt(0);
switch(ch)
{
case'y':
System.out.println("YES");
break;
case'n':
System.out.println("NO");
break;
case'c':
System.out.println("CANCEL");
break;
default:
System.out.println("INVALID CHARACTER");
}
sc.close();
}
}
package switchcase;
ReplyDeleteimport java.util.Scanner;
public class EvenOdd {
public static void main(String[] args) {
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter number");
n=sc.nextInt();
switch(n%2)
{
case 0:
System.out.println("Even Number");
break;
default:
System.out.println("Odd Number");
}
sc.close();
}
}
package switchcase;
ReplyDeleteimport java.util.Scanner;
public class Divisibility {
public static void main(String[] args) {
int n;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number ");
n=sc.nextInt();
switch(n%3)
{
case 0:
switch(n%5)
{
case 0:
System.out.println("Number is divisible by both 3 and 5 ");
break;
default:
System.out.println("Number only divisible by 3 ");
break;
}
break;
default:
switch(n%5)
{
case 0:
System.out.println("Number is only Divisible by 5 ");
break;
default:
System.out.println("Number is not divisible by both 3 and 5");
break;
}
break;
}
sc.close();
}
}
package switchcase;
ReplyDeleteimport java.util.Scanner;
public class GreatestnoConditional {
public static void main(String[] args) {
int a,b,c;
Scanner sc= new Scanner(System.in);
System.out.println("Enter 1st number");
a=sc.nextInt();
System.out.println("Enter 2nd number");
b=sc.nextInt();
System.out.println("Enter 3rd number");
c=sc.nextInt();
Object o = (a>b);
switch(o.toString().charAt(0))
{
case't':
Object o1 = (a>c);
switch(o1.toString().charAt(0))
{
case 't':
System.out.println("greatest number= "+a);
break;
default:
System.out.println("greatest number= "+c);
break;
}
break;
default:
Object o2 =(b>c);
switch(o2.toString().charAt(0))
{
case 't':
System.out.println("greatest number=" +b);
break;
default:
System.out.println("greatest number="+c);
break;
}
break;
}
sc.close();
}
}
package loops;
ReplyDeleteimport java.util.Scanner;
public class Factorial {
public static void main(String[] args) {
int n,i,f=1;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
n=sc.nextInt();
i=1;
while(i<=n)
{
f=(f*i);
i++;
}
System.out.println(n+"!"+"="+f);
sc.close();
}
}
Ankita Verma
ReplyDeleteimport java.util.Scanner;
class Switch
{
public static void main(String[]args)
{
char ch;
Scanner sc=new Scanner(System.in);
System.out.println("enter your choice");
ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
case 'Y':
System.out.println("Yes");
break;
case 'n':
case 'N':
System.out.println("No");
break;
case 'c':
case 'C':
System.out.println("Cancel");
break;
default:
System.out.println("wrong answer");
break;
}
}
}
//yogesh seroke
ReplyDelete//even odd
import java.util.Scanner;
class evenodd
{
public static void main(String[]args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
int i=sc.nextInt();
switch(i%2)
{
case 0:
System.out.println("even");
break;
default:
System.out.println("odd");
break;
}
}
}
//yogesh seroke
ReplyDelete//v and c
import java.util.Scanner;
class CheckVC
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
char x=sc.next().charAt(0);
switch(x)
{
case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U':
System.out.println("Vowel");
break;
default:
System.out.println("consonent value");
}
}
}
//yogesh seroke
ReplyDelete//greatest num
import java.util.Scanner;
class Greatnoo
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value of a");
int a=sc.nextInt();
System.out.println("enter the value of b");
int b=sc.nextInt();
switch(a/b)
{
case 0:
System.out.println("b is greater than a");
break;
default:
System.out.println("a is greater than b");
break;
}
}
}
//yogesh seroke
ReplyDelete//divisible by 3 and 5
import java.util.Scanner;
class CheckDIV
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
int a=3;
switch(a%3)
{
case 0:
switch(a%5)
{
case 0:
System.out.println("divisible by both");
break;
default:
System.out.println("only div by 3");
break;
}
break;
default:
switch(a%5)
{
case 0:
System.out.println("div by 5");
break;
default:
System.out.println("not div by any");
break;
}
break;
}
}
}
//yogesh seroke
ReplyDelete//greatest from three num
class Greatnoswitch
{
public static void main(String[]args)
{
int a=9, b=30, c=7;
switch(a/b)
{
case 0:
switch(b/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("b is greater");
break;
}
break;
default:
switch(a/c)
{
case 0:
System.out.println("c is greater");
break;
default:
System.out.println("a is greater");
break;
}
break;
}
}
}
//yogesh seroke
ReplyDelete//yes no cancle
import java.util.Scanner;
class yesnocancle
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the value");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
System.out.println("yes");
break;
case 'n':
System.out.println("no");
break;
case 'c':
System.out.println("cancle");
break;
default:
System.out.println("something incorrect");
break;
}
}
}
//yogesh seroke
ReplyDelete//leapyear
import java.util.Scanner;
class leapyear
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the year");
int year=sc.nextInt();
switch(year%4)
{
case 0:
System.out.println("leap year");
break;
default:
System.out.println("this is not a leap year,..");
}
}
}
//yogesh seroke
ReplyDelete//even odd
import java.util.Scanner;
class EO
{
public static void main(String[]arg)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter number...");
int num=sc.nextInt();
switch(num%2)
{
case 0:
System.out.println("even");
break;
default:
System.out.println("odd");
break;
}
}
}
WAP to check Greatest among three different numbers?
ReplyDeleteclass SwitchExample
{
public static void main(String args[])
{
int a=60,b=230,c=11;
//System.out.println(""+ (a>b));
Object o = a>b;
switch(o.toString())
{
case "true":
o = a>c;
switch(o.toString())
{
case "true":
System.out.println("a is greatest");
break;
default:
System.out.println("c is greatest");
break;
}
break;
default:
o = b>c;
switch(o.toString())
{
case "true":
System.out.println("b is greatest");
break;
default:
System.out.println("c is greatest");
break;
}
break;
}
}
}
Sandeep kelwa
ReplyDeleteThe solution to this program:-
class Greater
{
public static void main(String args[])
{
int a=20,b=100;
switch(a/b)
{
case 0:
System.out.println("b is greater");
break;
default:
System.out.println("a is greater");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass Calculator
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter No. 1=");
int no1=sc.nextInt();
System.out.println("Enter No. 2=");
int no2=sc.nextInt();
System.out.println("Selecte Symbol(+,-,*,/)");
String sym=sc.next();
int res;
switch(sym)
{
case "+" : res=no1+no2;
System.out.println("Addition is :"+res);
break;
case "-" : res=no1-no2;
System.out.println("Subtraction is :"+res);
break;
case "*" : res=no1*no2;
System.out.println("Multiplication is :"+res);
break;
case "/" : res=no1/no2;
System.out.println("Divisionis :"+res);
break;
default : System.out.println("Invalid Symbole");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass EvenOdd
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your Number :");
int no=sc.nextInt();
switch(no%2)
{
case 0:
System.out.println(" This no is Even");
break;
default:
System.out.println("This no. is Odd");
break;
}
}
}
import java.util.Scanner;
ReplyDeleteclass Display11
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter your Charactore");
char ch=sc.next().charAt(0);
switch(ch)
{
case 'y':
case 'Y':
System.out.println("Yes");
break;
case 'n':
case 'N':
System.out.println("No");
break;
case 'c':
case 'C':
System.out.println("Cancel");
break;
default:
System.out.println("wrong answer");
break;
}
}
}