Some Java Problems to practice(part 18)

Codynn
5 Min Read

I’ve included a list of some of the Java programs below. You may also view all of the Java programs on our mobile app. I strongly advise you to use our mobile app for a better experience.

Please click the link to get our app–> https://play.google.com/store/apps/details?id=com.allbachelor.javaapp&hl=en&gl=US

176. Write a program in java TO PRINT MULTIPLICATION TABLE OF A GIVEN NUMBER.

 import java.util.Scanner;  
     
   class MultiplicationTable {  
   public static void main(String[] args) {  
   Scanner sc = new Scanner(System.in);  
   System.out.println("Enter your number");  
   int num = sc.nextInt();  
   for (int i = 1; i   <= 10; i++) {  
   System.out.println(num + " * " + i + " = " + num * i);  
   }  
   }  
   }  

177. Write a program in java using to print first 19 even numbers.

import java.util.Scanner;  
     
   class EvenNumbers {  
   public static void main(String[] args) {  
   for (int i = 0; i   <= 19; i++) {  
   if (i % 2 == 0) {  
   System.out.println(i);  
   }  
     
   }  
   }  
   }  

178. Write a program in java to generate the series 1,8,27……………8th.

  
class Series
{
   public static void main(String args[])
   {

       for (int i = 1; i   <8 ; i++) {
           System.out.print(i*i*i + " ");
       }

   }
}  
  

179. Write a program in java to print all even numbers from 2 to 100 in descending order.

 import java.util.Scanner;  
     
   class EvenNumber {  
   public static void main(String[] args) {  
   for (int i = 100; i >= 2; i--) {  
   if (i % 2 == 0) {  
   System.out.println(i);  
   }  
   }  
   }  
   }  

180. Write a program in java to ask any string and count total no. of consonants.

class ConsonantsCount 
{ 
   public static void main(String args[]) 
   { 
       int cCount = 0; 
       String str = "Java Programs"; 
       str = str.toLowerCase(); 
       for(int i = 0; i < str.length(); i++) { 
           char ch = str.charAt(i); 
           if(ch == \'a\' || ch == \'e\' || ch == \'i\' || ch == \'o\' || ch == \'u\' ){ 
               System.out.print(""); 
           }else if(ch != \' \'){ 
               cCount++; 
           } 
       } 
       System.out.println("Number of consonants: " + cCount); 
   } 
}  

181. Write a program in java to generate the following series 11111,1111,111,11,1.

class Pattern {  
   public static void main(String[] args) {  
   for (int i = 1; i   <= 5; i++) {  
   for (int j = 1; j   <= i; j++) {  
   System.out.print("1");  
   }  
   System.out.println();  
   }  
   }  
   }  

182. Write a program to input any number and check whether the given no. is positive or negative.

import java.util.Scanner;  
     
   class PositiveNegative {  
   public static void main(String[] args) {  
   Scanner sc = new Scanner(System.in);  
   System.out.println("Enter your number");  
   int num = sc.nextInt();  
   if (num > 0) {  
   System.out.println("The number is positive");  
   } else {  
   System.out.println("The number is negative");  
   }  
   }  
   }  

183. Write a program in java to generate the following series 2,3,5,8,13…………10th term.

class FibonacciSeries{  
   public static void main(String args[])  
   {  
       int n1=2,n2=3,n3,i,count=10;  
       System.out.print(n1+" "+n2);  

       for(i=2;i   <count; ++i)  
       {  
           n3=n1+n2;  
           System.out.print(" "+n3);  
           n1=n2;  
           n2=n3;  
       }  
         

   }}  
  

184. Write a program in java TO ENTER ANY DIGIT AND PRINT SQUARE OF EVEN DIGITS.

import java.util.Scanner;  
  
class SumOfSquareOfEvenDigit{  
  public static void main(String[] args) {  
      int num = 0;  
      System.out.println("Enter number");  
      Scanner MyScanner = new Scanner(System.in);  
      num = MyScanner.nextInt();  
      int sum = 0;  
      while (num != 0) {  
          int rem = num % 10;  
          if (rem % 2 == 0) {  
              sum = sum + (rem * rem);  
          }  
          num = num / 10;  
      }  
      System.out.println("Sum of square of even digits is " + sum);  
  }  
       
  }  

185. Write a program in java to generate the following series 88888888,666666,4444,22.

class Series  
{  
   public static void main(String args[])  
   {  
       for (int i = 8; i>=2; i=i-2) {  
           for(int j =1; j  <=i; j++){  
               System.out.print(i);  
           }  
           System.out.println();  
       }  
             
       }  
}    
  
Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *