Write a program which converts all lowercase letter in a sentence to uppercase. For Example: 1) Consider a sentence "welcome to Java Programming!" its uppercase conversion is " WELCOME TO JAVA PROGRAMMING!" 2) If user inputs string like "Hello World!" it should print " HELLO WORLD!" public static void main(string[] args) String sentence,u_sentence; System.out.println("please enter your sentence :"); sentence=in.nextline(); u_sentence=sentence.touppercase(); System.out.println("to upper case :" + u_sentence);
Write a program which accepts an Integer which is an Angle and prints the Quadrant number in which it is. For Example: 1) If user input 30 then it should print 1. 2) If user input 197 then it should print 3 public static void main(string[] args) double angle; System.out.println("please enter the angle"); angle=in.nextdouble(); if(angle >=0 && angle <=90) System.out.println("the Quadrant number of this angle is : 1"); else if(angle >90 && angle <=180) System.out.println("the Quadrant number of this angle is : 2"); else if(angle >180 && angle <=270) System.out.println("the Quadrant number of this angle is : 3"); else if(angle >270 && angle <=360) System.out.println("the Quadrant number of this angle is : 4");
Complete the program which takes date in number format and then makes its addition of the digits until the last digit remains single and the print the number as lucky number. for example if the input is 777 then 7+7+7 =21 = 2+1 =3 so the answer is 3. Example: Enter the date(ddmmyy): 131083 Your lucky number is: 7 Example: Enter the date(ddmmyy): 111111 Your lucky number is: 6 public static void main(string[] args) int date,date_num,sum_mod=0,lucky=0,mod; System.out.println("please enter your b-date"); date=in.nextint(); while(date > 0) date_num=date%10; sum_mod=sum_mod+date_num;
date=date/10; System.out.println("sum " + sum_mod); while(sum_mod >0) mod=sum_mod%10; lucky=lucky+mod; sum_mod=sum_mod/10; System.out.println("Your lucky number is: " +lucky);
Write a program which calculates the sum of natural numbers which are divisible by 3 and 5 less than the number given as input. for example: 1. If user input 10 then output will be 23. 2. If user input 20 then output will be 78. public static void main(string[] args) int div_3_5, sum_div_3_5=0; System.out.println("enter div_3_5"); div_3_5 = in.nextint(); for( int d=3; d< div_3_5; d++) if((d % 3 == 0) (d % 5 == 0)) sum_div_3_5=sum_div_3_5+d; System.out.println("sum_div_3_5 " + sum_div_3_5);
Write a program which takes inputs of height and width of rectangle as integer and print the rectangle. Example: 1) If width = 10 and height = 5 then the rectangle is : ********** ********** 2) If width = 15 and height = 10 then the rectangle is : *************** *************** public static void main(string[] args) int width,height ; System.out.println("please enter the width"); width=in.nextint(); System.out.println("please enter the height"); height=in.nextint();
for(int i=0; i<width; i++) System.out.print("*"); System.out.println(); for(int j=0; j<height-2; j++) System.out.print("*"); for(int i=2; i<width; i++) System.out.print(" "); System.out.print("*"); System.out.println(); for(int i=0; i<width; i++) System.out.print("*"); System.out.println();
Write a program which validates whether the given input year is Leap or Not Leap. For Example: 1) if user inputs 2008 then program should print "Leap". 2) if user inputs 2009 then program should print "Not leap". public static void main(string[] args) int year; System.out.println("please enter year to check :"); year = in.nextint(); if(year % 4 ==0) System.out.println("this is leap year");
Write a program which takes input as integer and display the reverse triangle on the basis of input integer. Example: If user gives input 5 then the triangle should be like this: 12345-1234 --123 ---12 ----1 If user gives input 6 then the triangle should be like this: 123456-12345 --1234 ---123 ----12 -----1 public static void main(string[] args) int triangle; System.out.println("please enter number to draw triangle"); triangle= in.nextint(); int i; for (int t=1; t<=triangle ; t++) i=1; for(int v=1; v<=triangle; v++)
if (t>v) System.out.print("_"); else System.out.print(i++); System.out.println();
Write a program which takes two integers N and M and produces last samples of N of the integers from N-1 to N-M. for example: 1) if user inputs N = 10 M = 4 output will be 9 8 7 6 2) if user inputs N = 5 M = 2 output will be 4 3 public static void main(string[] args) int N,M; System.out.println("please enter N"); N=in.nextInt(); System.out.println("please enter N"); M=in.nextInt(); for(int i=n-1; i>=n-m; i--) System.out.println("integers from N-1 to N-M: " + i);
Write a java program takes input as integer and check whether the number is prime or not. Note: If the variable is prime then display "The number is prime." else display "The number is not prime.". public static void main(string[] args) int x; boolean check = true; System.out.println("enter number to check if prime or not"); x=in.nextint(); for (int i=2; i < x; i++) if(x % i == 0) check = false; break; if(check==false) else System.out.println("not prime"); System.out.println("prime");
Write a program which takes input as string and check if it is palindrome or not. If the string and the reverse of string are same then we say string is palindrome. If string is "level" then the output should be: palindrome If string is "helloworld" then the output should be: not a palindrome public static void main(string[] args) String palindrome; System.out.println("please enter string to check if it's palindrome or not"); palindrome = in.next(); boolean check=true; int n = palindrome.length(); int mid= n/2; for (int i =0; i<= n/2; i++) if(palindrome.charat(i)!= palindrome.charat(n -i -1)) check = false; if(check== true) else System.out.println("palindrome"); System.out.println("not palindrome");