3. Write a program that will print the following output 1 1 2 1 1 2 4 2 1 1 2 4 8 4 2 1 1 2 4 8 16 8 4 2 11 2 4 8 16 32 18 8 4 2 1, import java.util.Scanner;public class PracticeDemo { public static void getNumber(int number){ int middle=1; String start="1",end="1",output; System.out.println(start); for(int i=1;i<=number;i++){ middle=middle*2; output=start+" "+middle+" "+end; System.out.println(output); start=start+" "+middle; end=middle+" "+end; } } public static void main(String [] args){ Scanner sc=new Scanner(System.in); System.out.println("Enter the number"); int x=sc.nextInt(); getNumber(x); sc.close(); } }output:11 2 11 2 4 2 11 2 4 8 4 2 11 2 4 8 16 8 4 2 11 2 4 8 16 32 16 8 4 2 11 2 4 8 16 32 64 32 16 8 4 2 11 2 4 8 16 32 64 128 64 32 16 8 4 2 11 2 4 8 16 32 64 128 256 128 64 32 16 8 4 2 11 2 4 8 16 32 64 128 256 512 256 128 64 32 16 8 4 2 11 2 4 8 16 32 64 128 256 512 1024 512 256 128 64 32 16 8 4 2 1, I would say we should have i=1) && (d<31)); //||((m>=1) && (m<12));//||((y>=00) && (y<99)); if(!valid) System.out.print("Invalid date"); else { switch (dd) { case "01": System.out.print("First of "); switch (mm) { case "01": System.out.print("January,2020"); break; Feel free to comment, ask questions if you have any doubt. a program in Java to reverse any String without using StringBuffer? Factorial, which is for n! The best way we learn anything is by practice and exercise questions. *;class freqWORD{ int count=0; public void main()throws IOException { BufferedReader b=new BufferedReader (new InputStreamReader(System.in)); System.out.println("Enter a line"); String line=b.readLine(); System.out.println("Enter thew word to be searched"); String word=b.readLine(); line=" "+line +" " ; line=line.replace(word, "0"); for(int i=0; i0){ System.out.println("IS a power of 2"); } else System.out.println("NOT a power of 2"); }}}, if you try to keep dividing the number by 2 and the number perfectly divided by 2 with 0 as remainder until you get 1 in the end then it is power of 2 otherwise it is not.import java.util.Scanner;public class PowerOfTwo { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int num = scan.nextInt(); while(num%2==0 && num!=0) { num = num/2; } if(num == 1) System.out.println("Number is power of 2"); else System.out.println("Number is not power of 2"); }}, A Dynamic Solution:public class PrintStructure { public static final int START = 1; public static final int MAX = 10; public static final int STEP_SIZE = 3; public static void main(String[] args) { int noOfLoops = (MAX - START) / STEP_SIZE; noOfLoops++; int noOfPrintingStars = START; boolean startDecreasing = false; for (int i = 0; i < (noOfLoops * 2 - 1); i++) { for (int j = 0; j < noOfPrintingStars; j++) { System.out.print("*"); } System.out.println(); if (startDecreasing) { noOfPrintingStars = noOfPrintingStars - STEP_SIZE; } else { noOfPrintingStars = noOfPrintingStars + STEP_SIZE; } if (noOfPrintingStars == MAX) { startDecreasing = true; } } }}.
Cardigan Welsh Corgi Colors,
Schengen Visa Countries,
Roomba E6 Vs E5,
Bear Brook Valley Capacity,
Kenma Gif Cute,
Career Aptitude Test Reddit 2020,
Tokay Gecko Bite Poisonous,
Carn A' Mhaim, Ben Macdui,