Skip to main content

Posts

Showing posts with the label Programming

Patterns: Java Program To Print Patterns Of Numbers And Stars

Patterns are most important for interview point of view. To understand pattern problem you know only the basic tactic of how to solve pattern problem. In Java, it becomes a little bit easier to code patterns problems. In this article we discuss 20 basic pattern problem in java. Java Program: To Check If A Number Is Prime In Java Lets get start :) Patterns In Java 1. Left Triangle Star Pattern : First, let us begin with the basic and the commonly asked pattern program in  Java  i.e This is the basic pattern in java to write its code . Their is only two loops are used one for row and another for column. Let’s write the java code: import java.util.*; public class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); // write ur code here int n = scn.nextInt(); for (int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ System.out.print("*\t

Java Program: To Check If A Number Is Prime In Java

In this java program, we have one positive input and check whether the given number is prime or not. Read what is Prime Number . The simple case to check prime number we do, if (number % 2 == 0){ print("Not prime");} else { print("is prime");} But its complexity is much high if we use for loop . To decrease the complexity of the program read below question and solution. Tic Tac Toe Python 3: The Standard Tic-Tac-Toe Game in Python 3 Java Program: Question You've to check whether a given number is prime or not. A number "t" as input representing a count of input numbers to be tested. Number "n" as input "t" number of times. For each input value of n, print "prime" if the number is prime and "not prime" otherwise. Explanation and sample input Input Format : t n A number n .. t number of times Output Format : prime not prime not prime .. t number of times Constraint

Tic Tac Toe Python 3: The Standard Tic-Tac-Toe Game in Python 3

I just finished Tic tac toe game as my first python project. This is a very simple classic game, for beginners in programming tic-tac-toe game is the best choice. I am using Jupyter notebook, you can use any python ide like Pycharm, Spyder etc. Scenario of tic-tac-toe game: Your task is to write a simple program which pretends to play  Tic-tac-toe game with the user.  To make it easier for you. We have decided to simplify the game. Here are our assumptions. the computer should play a game using 'X' the user should play a game using 'O' the first move belongs to the computer, it always 'X' in the middle of the board.  all squares are numbered row by row, start with '1'. the user move is to enter the number of the square they choose, the number must be valid, that is it must be an integer, it must be greater than  0 and less than 10, and it cannot point to a field which is already occupied. the program checks the ga