Welcome to codebook here you will get the basic and important program for academics and mostly asked in exams. Along with it contains examination paper of UTD,RTU Kota.
Labels
- Android (31)
- Basic C programs (26)
- Exam Papers (16)
- 1st Sem Exam (11)
- DSA (8)
- Placement paper questions (5)
- Sorting (5)
- Star Pattern (3)
- Cmd (2)
How to create android app for website.?How to open website in android app
Just add webView to xml
Main Activity.Java
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
private WebView mywebView;
String url="www.google.com";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mywebView=findViewById(R.id.web);
mywebView.getSettings().setJavaScriptEnabled(true);
mywebView.getSettings().setSupportZoom(true);
mywebView.getSettings().setUseWideViewPort(true);
mywebView.getSettings().setLoadWithOverviewMode(true);
mywebView.loadUrl(url);
mywebView.setWebViewClient(new WebViewClient());
}
@Override
public void onBackPressed() {
if(mywebView.canGoBack()) {
mywebView.goBack();
} else {
super.onBackPressed();
}
}
}
Why my android app is not working.? Why my android app crashes.?
6.Xml file is not connected
How to make caluculator app using android.?
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value 1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Value2"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="*" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.java
package com.app.kapil.calculator;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
Button b1,b2,b3,b4,b5;
EditText t1,t2,t3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button1);
b2=(Button) findViewById(R.id.button2);
b3=(Button) findViewById(R.id.button3);
b4=(Button) findViewById(R.id.button4);
b5=(Button) findViewById(R.id.button5);
t1=(EditText) findViewById(R.id.editText1);
t2=(EditText) findViewById(R.id.editText2);
t3=(EditText) findViewById(R.id.editText3);
b1.setOnClickListener(new A());
b2.setOnClickListener(new B());
b3.setOnClickListener(new C());
b4.setOnClickListener(new D());
b5.setOnClickListener(new E());
}
class A implements View.OnClickListener
{
@Override
public void onClick(View arg0) {
int a,b,ans;
a=Integer.parseInt(t1.getText().toString());
b=Integer.parseInt(t2.getText().toString());
ans=a+b;
t3.setText(""+ans);
}
}
class B implements View.OnClickListener
{
@Override
public void onClick(View arg0) {
int a,b,ans;
a=Integer.parseInt(t1.getText().toString());
b=Integer.parseInt(t2.getText().toString());
ans=a-b;
t3.setText(""+ans);
}
}
class C implements View.OnClickListener
{
@Override
public void onClick(View arg0) {
int a,b,ans;
a=Integer.parseInt(t1.getText().toString());
b=Integer.parseInt(t2.getText().toString());
ans=a*b;
t3.setText(""+ans);
}
}
class D implements View.OnClickListener
{
@Override
public void onClick(View arg0) {
try{
int a,b,ans;
a=Integer.parseInt(t1.getText().toString());
b=Integer.parseInt(t2.getText().toString());
ans=a/b;
t3.setText(""+ans);
}
catch(Exception e){
Toast.makeText(MainActivity.this,"Enter a number other than 0 "+e,Toast.LENGTH_LONG).show();
}
}
}
class E implements View.OnClickListener
{
@Override
public void onClick(View arg0) {
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}
}
}
Output
How to setup android studio.? How to install android studio.? Error in installing android studio.? Windows/Linux/MacOs
- Java environment (JDK installed) Download Java
- Latest Android Studio(3.2 at this time) Download Android Studio
- Open cmd/terminal
- For Windows press window key+R and type cmd and run it.
- For Linux, search terminal run it
Launch the Java Control Panel on Mac (10.7.3 and above)
- Click on Apple icon on upper left of the screen.
- Go to System Preferences
- Click on the Java icon to access the Java Control Panel.
- Ctrl+Alt+S
- File->Setting
- Tools->Sdk Manager
How to click on the link in cmd.? How to click on link to verify Firebase CLI Login.?
Hey,
Once the same problem was with me..
I was deploying my project to firebase and it sends me the link to verify. But I was not able to click the link. After searching a bit I got this.
Follow these simple step
1. Search cmd
2. Right click on command prompt
3. Select run as administrator
4. Now you can start your work and you will be able to click any link and functional things here.
Hope that helps.
Thank you
What is Error of R in android
Hello friend,
This error is because you have something in your java file or xml file whose Resources are not found in the project.
And then
You can Build->Rebuild Project that might help.
How to get full date in format day/month/year OR year/month/day in javascript
Create a html file paste the following code in <script></script> tag
You have all the items day,date and year. You can concatenate the way you want.
If you have observed month is added +1 that's because in javascript month range is (0-11) and in actual we have 12 months.
Month range(0-11)
Date range(1-31)
Week range(0-6)
How to deploay project to firebase from my pc..? How to host project to firebase using command line from my pc.?
It sounds like very tough that how to host project from pc using command like. But in real it's just two step process.
Note:- Command line for windows and are cmd and terminal respectively.
Before moving ahead you must have installed NodeJS in your pc Download NodeJS.
If you have done that then use command node -v in cmd it will you version like v1.0.90.
If you got this that great you are ready to go ahead.
- Step1
- Login to firebase console
- Create a project
- Step 2
- Open your project folder in your pc
- Type cmd in top bar (www->kapilonline->cmd) and enter
- You will see a black screen command line interface is prompt
- Step 3
- Use command firebase login
- Use command firebase deploy
How to use firebase for website.? How to use firebase for android.? How to insert data in firebase.?
The time I am typing this post just 5 min. before I have resolved this or understood this.
So, As you are new to firebase or beginner then you need to know some of basic things.
1.Firebase is not SQL database
2.There is no query to insert data in firebase.
3.Firebase store data in tree structure there are nodes and child nodes.
Steps to follow for easy start
1.Login Firebase
2.Click Go to console
3.Create new project
4.Give any name to project
5.Click setting icon on right of Project overview
6.Choose IOS or ANDROID or Website for which you are using firebase
For website you need to include following sample details in website head section
Note:- your-project-name is here to show you sample details
<head>
<script>
var config = {
apiKey: "AIzaSyC5V6O48uU3wM2A1eeHzVKW_IfZWrO7X3s",
authDomain: "your-project-name.firebaseapp.com",
databaseURL: "https://your-project-name.firebaseio.com",
projectId: "your-project-name",
storageBucket: "your-project-name.appspot.com",
messagingSenderId: "3186427xxxx"
};
firebase.initializeApp(config);
</script>
</head>
For Android App
Note:-If you are in upgraded version of Android studio then click on "Tools->Firebase->Login->Connect to firebase".
OR
If above method does not work for you login firebase in browser and under Console select project
1.Goto project setting
2.Select android
3.Copy package name from android project app and paste it to register app
4.Download google-service JSON File
5.Paste that file under app folder in project folder of your project.
Note:-Now Click on Add Realtime database to your android project to connect your database to your project.
Coming to database and storage
1.Database where information is saved like name email phone etc.
2.Storage where image,pdf,file etc. is stored.
Data will not inserted untill you make following changes
1.Change database cloud beta to real database
2.Under rule section change read and write to true.
Want to know how to host website on firebase for free from your desktop.?
Comment below
Tcs question to print series 1,2,1,3,2,5,3,8...
int main()
{
int n,j=2,i,a=1,b=2,c;
int arr[20];
scanf("%d",&n);
arr[0]=a;
arr[1]=b;
for(i=1;i<=n;i++){
c=b-a;
arr[j]=c;
j++;
a=b;
b=c;
c=b+a;
arr[j]=c;
j++;
a=b;
b=c;
}
//display series
for(i=0;i<10;i++){
printf("%d,",arr[i]);
}
}
Tcs question - C program to reverse string using command line
int main(int argc,char *argv[])
{
int len;
char *ptr;//take pointer to traverse
ptr=argv[1];
len=strlen(argv[1]);
if(argc==1){
printf("Error:Please enter atleast one argument");
return 0;
}
while(len>=0){
printf("%c ",ptr[len--]);
}
return 0;
}
Tcs question C program to find LCM in command line
int main(int argc, char *argv[])
{
int lcm,i,num1,num2,max_value=0;
num1=atoi(argv[1]);
num2=atoi(argv[2]);
max_value=(num1>num2)?num1:num2;
while(1){//Always true till we get the lcm
if(max_value%num1==0&&max_value%num2==0){
printf("LCM is :%d",max_value);
break;
}
++max_value;
}
return 0;
}
Tcs question find out gcd of two number in c using command line
int main(int argc, char *argv[])
{
int gcd,i,num1,num2=0;
num1=atoi(argv[1]);
num2=atoi(argv[2]);
for(i=1;i<=num1 && i<=num2;i++){
if(num1%i==0 && num2%i==0){
gcd=i;
}
}
printf("GCD is :%d",gcd);
return 0;
}
Tcs question print string in c using command line
int main(int argc,char *argv[])
{
if(argc==1){
printf("Error:Please enter atleast one argument");
return 0;
}
//Note:- argv[0] is by default 0 our input string start storing from argv[1]. So it's better to start for loop from 1
int i,v=0,size=argc-1;
char *str;//intialize pointer
//allocate memory to which pointer points
str=(char*)malloc(v);//intially zero
//now re allocate memory as per size of input sting arguments
for(i=1;i<=size;i++){
int length=v+strlen(argv[i]);
str=(char*)realloc(str,length);
//now concatenate the string argument
strcat(str,argv[i]);
//give a namespace
strcat(str," ");
}
//now print string use %s not %concatenate
printf("%s\n",str);
return 0;
}
Link list of three nodes with insert display and delete
#include<stdlib.h>
#include<malloc.h>
struct node{
int label;
char oper;
int address;
struct node *next;
};
//shorting the name
typedef struct node node;
node *head;
//Display function
void display(){
if(head==NULL)
{
printf("There is no node \n");
}
//Create temporary node t
node *t=head;
while(t){
printf("%d\t",t->label);
printf("%c\t",t->oper);
printf("%d\t",t->address);
t=t->next;
}
}
//Insert function
void insert(){
int a,c;
char b;
//create new node
node *nnode=(node*) malloc(sizeof(node));
printf("Enter Label,Operator,Address\n\n");
scanf("%d",&a);//Label
getchar();
scanf("%c",&b);//oper
getchar();
scanf("%d",&c);//address
getchar();
printf("\n");
nnode->label=a;
nnode->oper=b;
nnode->address=c;
if(head==NULL){
nnode->next=NULL;
head=nnode;
}
else{
//insert at the end
node *t=head;
while(t->next){
//traverse until t->next=NULL
t=t->next;
}
t->next=nnode;//New node will be inserted at the end
nnode->next=NULL;
}
}
void remove(int l){
node *t=head;//store head so it do not change
node *p;
p=t;//Take head address to temp pointer to remove it
if(head==NULL){
printf("There is nothing to delete\n\n");
return;
}
if (t!=NULL && t->label==l){
//This is single or first node to delete t->NULL
free(t);
head=NULL;
return;
}
while(t->next!=NULL && t->label!=l){
p=t;
t=t->next;
}
if(t==NULL){
printf("Item is not available\n\n");
return;
}
/* if(t->label==l)
{
head=t->next;
free(t);
return;
}*/
p->next=t->next;
free(t);
return;
}
int main(){
int l,ch;
do{
printf("*Enter Your choice*\n1.Insert Node\t2.Display List\t3.Delete Node\t4.Exit\n");
printf("Choice:\t");scanf("%d",&ch);printf("\n");
switch(ch){
case 1:
insert();
break;
case 2:
printf("Display:-");
display();
printf("\n\n");
break;
case 3:
printf("Enter label to remove:-\t");
scanf("%d",&l);
remove(l);
break;
case 4:
exit(0);
default:
printf("Wrong choice try again\n");
}
}while(ch<=3);
}