import java.util.Scanner; class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); int n; System.out.println("Enter no :"); n = myObj.nextInt(); int sum = 1,i,count=0,sub; for (i = 3; i <= n; i = i + 2) { count++; if (count == 2) { sub = sum - i; sum = sub; coRead more
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
int n;
System.out.println("Enter no :");
n = myObj.nextInt();
int sum = 1,i,count=0,sub;
for (i = 3; i <= n; i = i + 2)
{
count++;
if (count == 2)
{
sub = sum - i;
sum = sub;
count = 0;
continue;
}
sum = sum + i;
}
System.out.println("Sum is: " + sum);
}
}
import java.io.FileNotFoundException; public class Main { Main(String msg) { msg = "I AM JAVA"; System.out.println(msg); } public static void main(String[] args) throws Exception { try { // Suppose here you are looking for any resource for eg.File // If program is unable to find file throw new FileNRead more
import java.io.FileNotFoundException;
public class Main {
Main(String msg) {
msg = "I AM JAVA";
System.out.println(msg);
}
public static void main(String[] args)
throws Exception {
try {
// Suppose here you are looking for any resource for eg.File
// If program is unable to find file
throw new FileNotFoundException();
} catch (FileNotFoundException e) {
throw new Exception("File not found");
} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
// This block will get get executed whether exception occures or
// not.
System.out.println("i will get printed");
}
}
}
CODECHEF PRACTICE PROBLEM WEEK 6 AND 7:
CODECHEF PRACTICE PROBLEM WEEK 6 AND 7 SOLUTION :
CODECHEF PRACTICE PROBLEM WEEK 6 AND 7 SOLUTION :
See lessWrite a program to implement Binary Search Tree.
#include <iostream> using namespace std; class BST { int data; BST *left, *right; public: BST(); BST(int); BST* Insert(BST*, int); void Inorder(BST*); }; BST ::BST() : data(0) , left(NULL) , right(NULL) { } BST ::BST(int value) { data = value; left = right = NULL; } BST* BST ::Insert(BST* rootRead more
Java Retrieve the odd numbers till given input number. add and subtract it consecutively and return the result. Input:9 Output:1+3-5+7-9=-3
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); int n; System.out.println("Enter no :"); n = myObj.nextInt(); int sum = 1,i,count=0,sub; for (i = 3; i <= n; i = i + 2) { count++; if (count == 2) { sub = sum - i; sum = sub; coRead more
Java Create a class with a main( ) that throws an object of class Exception inside a try block. Give …
import java.io.FileNotFoundException; public class Main { Main(String msg) { msg = "I AM JAVA"; System.out.println(msg); } public static void main(String[] args) throws Exception { try { // Suppose here you are looking for any resource for eg.File // If program is unable to find file throw new FileNRead more
C Program for Depth First Binary Tree Search using Recursion.
#include <stdio.h> #include <stdlib.h> struct node { int a; struct node *left; struct node *right; }; void generate(struct node **, int); void DFS(struct node *); void delete(struct node **); int main() { struct node *head = NULL; int choice = 0, num, flag = 0, key; do { printf("\nEnterRead more
C Program to Find the Largest value in a Tree using Inorder Traversal.
#include <stdio.h> #include <stdlib.h> struct node { int info; struct node *left, *right; }; struct node *createnode(int key) { struct node *newnode = (struct node*)malloc(sizeof(struct node)); newnode->info = key; newnode->left = NULL; newnode->right = NULL; return(newnode); }Read more