|
Member 13501540 wrote: How? By reading the HTML, deciding which tags you want to keep, and using them to create the XML. There are libraries to read HTML and write XML, so all you need is to work out what needs to be transformed.
|
|
|
|
|
Well,thanks.
|
|
|
|
|
Create a function :
1. Int fact (int y) - to return the factorial of y .
2. Void printspecial() - by ivoking the function fact () , print all special numbers between s (start limit) and l ( last limit). The function reads starts (s) and last (l) limits. ( If sum of factorial of each digits of a numbers is equal to the number itself , the number is special ) .
Exp : input n = 145 = 1! +4! +5!= 1+24+120= 145, so 145 is special number .
Write a function Print () to I put start and end limits and by ivoking suitable function and print special numbers between start and end limits .
|
|
|
|
|
Sorry, we don't do your homework for you. Your homework is for you to learn stuff, not for us.
Try it yourself. If you get stuck somewhere in the middle feel free to ask a more specific question.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Jbdomnic123 wrote: Hi all can anyone solve this for me plz in java
Yes I can solve it. I would expect others can as well especially if they already know what a factorial is.
|
|
|
|
|
Not sure what's going wrong with my code-any suggestions? This is a basic calculator in Android Studio. It needs to be able to do multi-number operations(using order of operations). Currently, if you enter 2+2*6, it'll only do 2*6. Also, when you hit the Clear button, the 0 from the display stays tacked on, and I'm not sure how to get rid of it.Thanks!
package com.example.10012698.calculatorproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonadd, buttonsubtract, buttonmultiply,
buttondivide, buttonequals, buttonclear;
TextView display;
String displaytext="";
double result;
double x, y;
ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
buttonadd = (Button) findViewById(R.id.buttonadd);
buttonsubtract = (Button) findViewById(R.id.buttonsubtract);
buttonmultiply = (Button) findViewById(R.id.buttonmultiply);
buttondivide = (Button) findViewById(R.id.buttondivide);
buttonclear = (Button) findViewById(R.id.buttonclear);
buttonequals = (Button) findViewById(R.id.buttonequals);
display = (TextView) findViewById(R.id.display);
display.setOnClickListener(this);
list = new ArrayList<>();
}
public void onClick(View view)
{
if(!(view.equals(buttonclear)&&!(view.equals(buttonequals))))
{
display.setText(display.getText()+""+((Button)view).getText());
if(displaytext.equals("0"))
{
display.setText(" ");
}
if(view.equals(buttonclear))
{
display.setText(" ");
}
if(view.equals(buttonequals))
{
displaytext= displaytext.substring(0,displaytext.length()-1);
StringTokenizer operators= new StringTokenizer(displaytext, "+-*/",true);
while(operators.hasMoreTokens())
{
list.add(operators.nextToken());
}
for(int j=0; j<list.size()-1; j++)
{
if (list.get(j).equals("*") || list.get(j).equals("/"))
{
x = Double.parseDouble(list.get(j - 1));
y = Double.parseDouble(list.get(j + 1));
if (list.get(j).equals("*"))
{
result+=(x*y);
}
if (list.get(j).equals("/"))
{
result+=(x/y);
}
}
}
for(int k=0;k<list.size()-1;k++)
{
if (list.get(k).equals("+") || list.get(k).equals("-"))
{
x = Double.parseDouble(list.get(k - 1));
y = Double.parseDouble(list.get(k + 1));
if (list.get(k).equals("+"))
{
result+=(x+y);
}
if (list.get(k).equals("-"))
{
result+=(x-y);
}
}
}
}
display.setText(""+result);
}
}
|
|
|
|
|
Your code is not clear to understand, you need to try a bit more diagnosis to narrow down where the problem is. Also, this question (and the one below) really belong in the Android forum[^].
|
|
|
|
|
Member 13476776 wrote: Currently, if you enter 2+2*6, it'll only do 2*6
I don't believe that the code you posted does that.
Member 13476776 wrote: displaytext= displaytext.substring(0,displaytext.length()-1);
The code you posted never sets displaytext. So it will always be empty. You should have been getting the value from 'display' (presumably.)
Member 13476776 wrote: list.add(operators.nextToken());
You never clear 'list'. That is going to be a problem. I doubt that 'list' should even exist anywhere except the method that parses the result.
You never clear 'result'
Your algorithm is incorrect. It does the following
1. Start = 2+2*6
2. Parse multiplication/division: result += '2*6'
3. Parse addition/subtraction: result += '2+2'
That would leave result=16 (should be 14).
|
|
|
|
|
I am not sure of the logic. Please help.
My xml is as below:
<?xml version="1.0" encoding="UTF-8"?>
-<LinearLayout tools:context="com.example.sisir.calculatorproject.MainActivity" android:orientation="vertical" android:layout_height="match_parent" android:layout_width="match_parent" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat.Display2" android:text="0" android:gravity="right" android:layout_marginTop="50dp" android:layout_marginRight="20dp" android:layout_marginLeft="20dp" android:id="@+id/display"/>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginTop="30dp" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="1" android:id="@+id/button1" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="2" android:id="@+id/button2" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="3" android:id="@+id/button3" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" + " android:id="@+id/buttonadd" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="4" android:id="@+id/button4" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="5" android:id="@+id/button5" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="6" android:id="@+id/button6" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" - " android:id="@+id/buttonsubtract" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="7" android:id="@+id/button7" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="8" android:id="@+id/button8" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="9" android:id="@+id/button9" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" * " android:id="@+id/buttonmultiply" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="C" android:id="@+id/buttonclear" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="0" android:id="@+id/button0" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="=" android:id="@+id/buttonequals" android:onClick="onClick"/>
<Button android:layout_height="wrap_content" android:layout_width="wrap_content" android:text=" / " android:id="@+id/buttondivide" android:onClick="onClick"/>
</LinearLayout>
-<LinearLayout android:orientation="vertical" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_marginRight="20dp" android:layout_marginLeft="20dp">
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Calculator App" android:gravity="center_horizontal" android:layout_marginTop="15dp" android:id="@+id/title" android:layout_marginBottom="5dp"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Sisira Mandapaka" android:gravity="center_horizontal" android:id="@+id/name" android:layout_marginBottom="5dp"/>
<TextView android:layout_height="wrap_content" android:layout_width="match_parent" android:textAppearance="@style/TextAppearance.AppCompat" android:text="Block 2A" android:gravity="center_horizontal" android:id="@+id/block" android:layout_marginBottom="5dp"/>
</LinearLayout>
</LinearLayout>
and my java file is as below
package com.example.sisir.calculatorproject;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
Button button0, button1, button2, button3, button4, button5, button6,
button7, button8, button9, buttonadd, buttonsubtract, buttonmultiply,
buttondivide, buttonequals, buttonclear;
TextView display;
String displaytext="";
double result;
double x, y;
ArrayList<String> list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button0 = (Button) findViewById(R.id.button0);
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
button3 = (Button) findViewById(R.id.button3);
button4 = (Button) findViewById(R.id.button4);
button5 = (Button) findViewById(R.id.button5);
button6 = (Button) findViewById(R.id.button6);
button7 = (Button) findViewById(R.id.button7);
button8 = (Button) findViewById(R.id.button8);
button9 = (Button) findViewById(R.id.button9);
buttonadd = (Button) findViewById(R.id.buttonadd);
buttonsubtract = (Button) findViewById(R.id.buttonsubtract);
buttonmultiply = (Button) findViewById(R.id.buttonmultiply);
buttondivide = (Button) findViewById(R.id.buttondivide);
buttonclear = (Button) findViewById(R.id.buttonclear);
buttonequals = (Button) findViewById(R.id.buttonequals);
display = (TextView) findViewById(R.id.display);
display.setOnClickListener(this);
list = new ArrayList<>();
}
public void onClick(View view)
{
if(!(view.equals(buttonclear)&&!(view.equals(buttonequals))))
{
display.setText(display.getText()+""+((Button)view).getText());
if(displaytext.equals("0"))
{
display.setText(" ");
}
if(view.equals(buttonclear))
{
display.setText(" ");
}
if(view.equals(buttonequals))
{
displaytext= displaytext.substring(0,displaytext.length()-1);
StringTokenizer operators= new StringTokenizer(displaytext, "+-*/",true);
while(operators.hasMoreTokens())
{
list.add(operators.nextToken());
}
for(int j=0; j<list.size()-1; j++)
{
if (list.get(j).equals("*") || list.get(j).equals("/"))
{
x = Double.parseDouble(list.get(j - 1));
y = Double.parseDouble(list.get(j + 1));
if (list.get(j).equals("*"))
{
result+=(x*y);
}
if (list.get(j).equals("/"))
{
result+=(x/y);
}
}
}
for(int k=0;k<list.size()-1;k++)
{
if (list.get(k).equals("+") || list.get(k).equals("-"))
{
x = Double.parseDouble(list.get(k - 1));
y = Double.parseDouble(list.get(k + 1));
if (list.get(k).equals("+"))
{
result+=(x+y);
}
if (list.get(k).equals("-"))
{
result+=(x-y);
}
}
}
}
display.setText(""+result);
}
}
|
|
|
|
|
|
Hi, I'm searching for an application (or plugin at Eclipse / Netbeans) where I can analyze the structure of a class. It is important that I can see the package dependencies. Plugins I tried just give me an overview 1:1 or 1:n beetween the classes, but no information about the package dependence at a class.
A sample:
Class A
{
JButton btn;
void test()
{
btn = new JButton(myicon, „hello world");
String text = btn.getText();
btn.setText();
ArrayList<String> obj = new ArrayList<String>();
obj.add(„first");
obj.add(text);
}
void myfunc()
{
System.out.println(„test");
}
}
What I need here:
All foreign classes, functions, or constants (means all that are not defined at A) which are used through class A, are shown in a list.
myfunc() is not necessaray to show because it is definied at A - but it is doesn't matter if it is shown - that's okay.
It is not necessary that this tool (or plugin) shows it over a GUI.
Class ; Function ;
javax.swing.JButton ; init<icon, string=""> // Constructor
javax.swing.JButton ; getText() ;
javax.swing.JButton ; setText(String) ;
java.util.ArrayList ; init<>
java.util.ArrayList ; add(Object) ;
System.out ; println(String);
NOTE: I need no reverse engineering of a JAR file - I like to analyze my own java source files.
Thank you in advance!
|
|
|
|
|
|
Hager.Harald wrote: NOTE: I need no reverse engineering of a JAR file - I like to analyze my own java source files.
That is conceptually impossible.
Things like IDEs use an incremental compiler to validate the edit window as you type, so to that it can resolve, if possible, dependencies. The process might not create the final binary but it does involve a substantial amount of the same processing to get to the point where it can resolve such things.
Keeping in mind of course that the incremental compiler must also have a context to resolve dependencies, so java API libraries and other libraries that might be used.
Also keep in mind your example is simplistic and more significant applications will often use dependencies that cannot be resolved until the application runs.
|
|
|
|
|
Thank you for your answer (especially for your description how it works). This will help me to find an appropiate tool for my aims.
2017-10-18 Update: JArchitect has complied what I needed (but it is commercial)
modified 18-Oct-17 5:53am.
|
|
|
|
|
import java.util.*;
class One
{
static String city;
public static void main(String args[])
{
city=args[0];
Two t= new Two();
}
}
class Two extends One
{
if(city=="Banglore")
Two()
{
System.out.println("Hello BANGLORE");
}
}
|
|
|
|
|
Good job the error is blindingly-obvious, since you didn't bother to tell us what error you're getting!
Member 13451299 wrote:
class Two extends One
{
if(city=="Banglore")
You can't put an if statement directly inside a class. It has to be in a method.
The Java™ Tutorials[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
import java.util.*;
class One
{
public static String city;
public static void main(String args[])
{
city=args[0];
Two t= new Two();
}
}
class Two extends One
{
public Two()
{
if(city=="Banglore")
System.out.println("Hello BANGLORE");
}
}
|
|
|
|
|
what is the advantage of declaring each variable in separate line?
Zaki
|
|
|
|
|
|
I have been coding java for a few months and have a good understanding of it. I just have a few questions on certain things I wanna do.
I need help understanding the A* algorithm and how to code it. I'm trying to code mobs with AI that follow the player around.
I need to know how to implement sounds via the source code.
If it is necessary to know this, know that I am using Eclipse to code and Processing for graphics and stuff like that.
Any help will be greatly appreciated!
|
|
|
|
|
You need to use Google to find information about different algorithms, as they are not specific to Java. And for specific Java questions Google should also lead you to the documentation pages, such as Trail: Sound (The Java™ Tutorials)[^].
|
|
|
|
|
Gametron13 wrote: I need help understanding the A* algorithm and how to code it
Following provides examples in google
A* algorithm java
Just as a suggestion if you have never programmed before then doing what you are doing is is going to be rather ambitious. So you should expect that it will be difficult. Focusing on one part and making it as simple as possible, with the goal of making it better in the future might be more rewarding especially if the goal it to learn how to program.
|
|
|
|
|
HashMap Internal working. and which scenario use in java tech.
|
|
|
|
|
Member 13437687 wrote: HashMap Internal working
Yes it is working.
Member 13437687 wrote: and which scenario use in java tech.
The one that requires a hash. Find the problem first then the solution. Not the other way around.
Or conversely google for when to use it.
|
|
|
|
|