Sunday, 30 October 2016
Friday, 14 October 2016
Monday, 10 October 2016
Question:-
You have an answering protocol when your mobile rings.
1. You never answer it when you are sleeping.
2. You answer it in the morning, only if your mother calls.
3. All other times you answer it.
Write a Java program to decide whether you must answer the phone call or not.
Input specification:
3 Boolean variables - isMom, isAsleep, isMorning
Output specification:
true if you answer, false if you do not answer.
Sample input:
false
false
false
Sample output:
true
Source Code:-
import java.util.*;
class CallAns{
public static void main(String []args){
Scanner s=new Scanner(System.in);
boolean isMom=s.nextBoolean(),isAsleep=s.nextBoolean(),isMorning=s.nextBoolean();
System.out.println(isAsleep?false:(isMorning?isMom:true));
}
}
Saturday, 8 October 2016
Question:-
Source Code:-
import java.util.*;
class Vowels{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
String str=s.nextLine();
int count=0;
String temp="";
for(char c:str.toCharArray()){
if("aAeEiIoOuU".contains(c+"")){
count++;
temp=temp+c+" ";
}
}
System.out.println(count+"\n"+temp);
}
}
Write a program to print the vowels used in the given string of input. Input Specification : Input will be a sentence. Output Specification : Your program should print the total number of vowels in the sentence (repetitions allowed) in first line and in second line print all the vowels used separated by spaces. Sample Input : Elephant Is a Huge Animal Sample Output: 10 E e a I a u e A i a
Source Code:-
import java.util.*;
class Vowels{
public static void main(String[] args){
Scanner s=new Scanner(System.in);
String str=s.nextLine();
int count=0;
String temp="";
for(char c:str.toCharArray()){
if("aAeEiIoOuU".contains(c+"")){
count++;
temp=temp+c+" ";
}
}
System.out.println(count+"\n"+temp);
}
}
Subscribe to:
Posts (Atom)